使用带有http模块的express时,TypeScript编译错误

时间:2016-10-11 02:37:20

标签: typescript

TypeScript服务器端代码:

import * as express from 'express';
import * as http from 'http';
var app = express();
var server = http.createServer(app);

运行tsc时运行此错误:

express Argument of type 'Application' is not assignable to parameter of type

1 个答案:

答案 0 :(得分:0)

这是由于打字文件中现已修补bug。要解决此问题,您需要安装快速的GitHub提交。

typings install github:DefinitelyTyped/DefinitelyTyped/express-serve-static-core/express-serve-static-core.d.ts#58bf29ff6e6d7031bb7ec463732625bb2a0001d0 --global --save

使用typings searchtypings install以正常方式安装express的其他依赖项。确保在每个依赖项上使用--global标志,并安装off dt而不是npm。最后,你的typings.json看起来像这样:

{
  "dependencies": {},
  "globalDependencies": {
    "express": "registry:dt/express#4.0.0+20160708185218",
    "express-serve-static-core": "github:DefinitelyTyped/DefinitelyTyped/express-serve-static-core/express-serve-static-core.d.ts#58bf29ff6e6d7031bb7ec463732625bb2a0001d0",
    "mime": "registry:dt/mime#0.0.0+20160316155526",
    "node": "registry:env/node#6.0.0+20160918225031",
    "serve-static": "registry:dt/serve-static#0.0.0+20160606155157",
  }
}