Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/453.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将应用程序表示为http.createServer的参数_Javascript_Node.js_Express_Typescript_Typescript Typings - Fatal编程技术网

Javascript 将应用程序表示为http.createServer的参数

Javascript 将应用程序表示为http.createServer的参数,javascript,node.js,express,typescript,typescript-typings,Javascript,Node.js,Express,Typescript,Typescript Typings,当我想使用express.Application作为http.createServer的参数时,我有以下错误: 错误TS2345:类型为“Application”的参数不能分配给类型为“(请求:IncomingMessage,响应:ServerResponse)=>void”的参数。 我的代码: import * as express from "express" let app: express.Application = express(); ... import * as http fro

当我想使用express.Application作为http.createServer的参数时,我有以下错误:

错误TS2345:类型为“Application”的参数不能分配给类型为“(请求:IncomingMessage,响应:ServerResponse)=>void”的参数。

我的代码:

import * as express from "express"
let app: express.Application = express();
...
import * as http from "http"
let httpServer = http.createServer(app);
httpServer.listen(process.env.HTTP_PORT, (): void => {
    console.log(`HTTP Listen on ${process.env.HTTP_PORT}`)
});
typings.json:

{
  "dependencies": {
    "body-parser": "registry:npm/body-parser#1.15.2+20160815132839",
    "express": "registry:npm/express#4.14.0+20160911114220"
  },
  "globalDependencies": {
    "dotenv": "registry:dt/dotenv#2.0.0+20160327131627",
    "errorhandler": "registry:dt/errorhandler#0.0.0+20160316155526",
    "express-serve-static-core": "registry:dt/express-serve-static-core#4.0.0+20160914120416",
    "method-override": "registry:dt/method-override#0.0.0+20160317120654",
    "morgan": "registry:dt/morgan#1.7.0+20160524142355",
    "node": "registry:dt/node#6.0.0+20160921192128"
  }
}
我解决它。 只需要更新打字。我当前的typings.json文件:

{
  "globalDependencies": {
    "dotenv": "registry:dt/dotenv#2.0.0+20160327131627",
    "errorhandler": "registry:dt/errorhandler#0.0.0+20160316155526",
    "express": "registry:dt/express#4.0.0+20160708185218",
    "express-serve-static-core": "registry:dt/express-serve-static-core#4.0.0+20160916114806",
    "method-override": "registry:dt/method-override#0.0.0+20160317120654",
    "morgan": "registry:dt/morgan#1.7.0+20160524142355",
    "node": "registry:dt/node#6.0.0+20160921192128",
    "serve-favicon": "registry:dt/serve-favicon#0.0.0+20160316155526"
  },
  "dependencies": {
    "body-parser": "registry:npm/body-parser#1.15.2+20160815132839",
    "serve-static": "registry:npm/serve-static#1.11.1+20160810053450"
  }
}

看起来你打字的不同之处在于你降低了速成版的等级。是这样吗?如果你能提供更多关于改变了什么以及为什么改变的信息,那会很有帮助。