【问题标题】:Property 'close' does not exist on type 'Application'“应用程序”类型上不存在属性“关闭”
【发布时间】:2017-04-12 15:45:28
【问题描述】:

我是这样导入 expressjs 的:

import { Request, Response, Application, Router } from 'express';
const app: Application = require('express')();

在 typings.json 中:

 "express": "registry:npm/express#4.14.0+20160925001530",

当我输入 app.close() 我得到:

[ts] Property 'close' does not exist on type 'Application'.
  • 我该如何解决这个问题?

  • 我可以在哪里举报? (如果是错误)

  • 我是唯一一个在打字稿打字上苦苦挣扎的人吗?

【问题讨论】:

    标签: express typescript typescript-typings


    【解决方案1】:

    提供的Application的定义没有close方法...Server有,(app:Application).listen返回一个Server。

    start(){
        server = app.listen(options.port, function () {
            debug('Server listening on port ' + options.port)
        })
    }
    stop(){
        server.stop();
    }
    

    您可以报告绝对类型为here 的类型。这是来自npm的包。

    打字稿很难。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-26
      • 1970-01-01
      • 2017-02-26
      • 1970-01-01
      • 1970-01-01
      • 2021-11-29
      • 1970-01-01
      相关资源
      最近更新 更多