Tag: 打字

用于Typings CLI实用程序的命令使typings文件夹与typings.json匹配

我有一个使用Typescript处理repo的大型团队,没有人将/typings文件夹检入团队的共享存储库,他们只检查typings.json文件,该文件指定项目所需的每个定义集的版本信息。 有时候有人会从typings.json删除一个定义集,因为他们正在处理的项目部分不再使用这个库(或者我们find了一个更好的定义集),使用 typings uninstall –global –save dt~whatever ,并且在他们的本地机器上工作正常, 但是当他们推typings.json和我或别人拉下来,当我们然后运行typings install ,命令只将新的定义添加到typings文件夹中,并且不会从typings文件夹中删除typings.json不再存在的typings.json 。 是否有一个命令,我可以运行添加新的定义集,并删除已删除的设置,通过将当前的typings.json从typings.json的状态typings.json当typings.json命令是最后一次运行? 目前我们只是让每个人都删除整个typings文件夹,并在每次拉动时再次运行typings install ,但是由于我们现在有很多定义集,所以效率有点低下。 注:我们尝试typestypings uninstall和typings uninstall –save但只是抛出错误(看来你可能只能指定具体的定义集来卸载)。

meteor:在打字中写meteor法时,找不到模块纤维/未来

我用angular2使用typecript es6和我遇到这个错误,同时为asynchronous函数写一个meteor方法。 我在插入查询中遇到了一个同步问题,因为当名称相同时,它在插入时不提供给我一个错误。 所以我决定使用光纤和未来,但打字稿不断给我一个错误,它无法find纤维/未来的模块。 我已经试过meteornpm安装光纤,meteornpm安装未来,meteor添加ostrio:neo4jdriver@1.0.2-纤维,但没有任何工作。 如果有任何解决scheme,请告诉我。 如果有其他方法可以用来解决这个问题,请告诉我。 import { Emails } from '../collections/emails.collection'; import { check } from 'meteor/check'; import { Meteor } from 'meteor/meteor'; import Future from 'fibers/future'; Meteor.methods({ loadEmailTemp: function(tempn: string){ let temp = Emails.findOne({tempname: tempn}); return temp; }, getAllTemplates: function() { let temps = Emails.find({}).fetch(); return temps; }, newTemplate: function(tempn: string) { […]

预渲染失败,因为错误:错误:无法find模块

我正在尝试使用Visual Studio 2017和ASP.NET Core在本地机器上运行Angular Universal示例项目。 链接在这里: https : //github.com/angular/universal 方向看起来非常直接,克隆它,运行npm -i && dotnet恢复,然后按F5。 不幸的是,这不适合我。 当请求一个页面并试图预渲染的时候,它会抛出一个错误。 我去哪儿了? 堆栈跟踪如下。 Executed action AspCoreServer.Controllers.HomeController.Index (Asp2017) in 1725.3321ms fail: Microsoft.AspNetCore.Server.Kestrel[13] Connection id "0HL4JNIGV3L20": An unhandled exception was thrown by the application. System.Exception: Call to Node module failed with error: Prerendering failed because of error: Error: Cannot find module 'C:\Users\me\Documents\projects\ATS\aspnetcore-angular2-universal\aspnetcore-angular2-universal\Client\dist\main-server' at […]

在类中对RESTful API方法进行sorting的最佳实践

我在TypeScript中构build了一个Node.js网站,它公开了一个RESTful API。 将不同的方法分离到不同的类/文件的最佳实践是什么? 我想为每个资源我需要创build一个单独的类。 例如: class Customers{ router.get('/customers'); router.post('/customers'); router.put('/customers'); router.delete('/customers'); } class Orders{ router.get('/orders'); router.post('/orders'); router.put('/orders'); router.delete('/orders'); } 这是真的? 而如果我有许多资源只包含一个方法,每一个? 例如: router.get('/orders'); router.post('/customers'); router.put('/products'); router.delete('/employees'); 编辑:我被回答,我可以把所有的路线在一个单一的文件,只是把处理程序分成多个文件。 所以我的问题是:如何命令/将它们LOGICALLY分为不同的文件(关于我在我的问题中写的例子)? 注意:我不需要一个技术性的程序化信息,而是一个逻辑分离的抽象解释。

如何为中间件编写TypeScript定义,将属性添加到响应中?

我想用TypeScript的快递来expression快感。 它缺乏types,所以我想写我自己的。 只是让它编译是微不足道的。 这个中间件装饰物业boom的res物体(来自繁荣模块 ): var express = require('express'); var boom = require('express-boom'); var app = express(); app.use(boom()); app.use(function (req, res) { res.boom.notFound(); // Responsds with a 404 status code }); 但与打字稿我需要把它,因为无论http.ServerResponse和Express.Response有兴旺的属性,当然: return (<any>res).boom.badRequest('bla bla bla'); 最干净的方法是干什么? 哪些是其他types的中间件,正在做类似的事情?

更改swagger 2.0文档pathurl

这就是我configurationswagger的方法: const openapi = Openapi.initialize({ paths: openApiPaths, app, apiDoc, }); const openApiSpec = openapi.apiDoc; console.log(openApiSpec); app.use(swaggerUI(openApiSpec)); 我如何更改基本path/docs/ to /projectName/docs/ ? 我没有find任何相关的答案 编辑 我的api文档在它自己的文件中描述如下: export const apiDoc = { 'x-express-openapi-additional-middleware': [checkBodyValidity], swagger: '2.0', basePath: '/api/v1', info: { title: 'Documentation Rest API', version: 'v1', }, paths: {}, definitions: {} } CheckBodyValidity是一种检查请求参数有效性的中间件(与我的问题无关): export const checkBodyValidity: any = (req, […]

在TypeScript中创build一个Swagger Web服务的正确方法是什么?

我是用TypeScipt编写的项目的一部分,我正在尝试添加将与Swagger兼容的TypeScript Web服务器。 考虑到易维护性,实施它的最基本的策略是什么。 对于Typescript,我注意到存在用于从TypeScript接口生成JSON模型的“Typson”库。 对于Swagger,我曾尝试使用'swagger-node-restify'库,因为它支持将JSON模型添加到swagger中。 但是,我遇到一些问题: Typson不支持导入的 typeScript 语法 – ( import {Server} from "restify" ) 我试图实现'swagger-node-restify'示例(Pet Example),但localhost:8080 / api-docs.json GET请求的RESPONSE缺lessAPI的所有SPEC数据。 {"apiVersion":"0.1","swaggerVersion":"1.1","basePath":"http://localhost:8080","apis":[{"path":"/api-docs.{format}/pet","description":"none"}]}