gpt4 book ai didi

javascript - 将应用程序表达为 http.createServer 的参数

转载 作者:行者123 更新时间:2023-11-28 05:31:35 24 4
gpt4 key购买 nike

当我想使用express.Application作为http.createServer的参数时,出现此错误:

错误 TS2345:“应用程序”类型的参数无法分配给“(请求: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"
}
}

关于javascript - 将应用程序表达为 http.createServer 的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39656643/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com