【问题标题】:Type definition not found找不到类型定义
【发布时间】:2018-04-05 08:35:16
【问题描述】:

我开始使用带有 expressJs 的 VS Code。我决定使用 Route.use 函数将路由拆分到不同的文件中。 在新文件中,我想让智能感知向我建议应用程序参数中的所有方法,因此我添加了 /**@param type {Express} app */ jsdoc。关键是 Intellisense 无法找到类型定义。我该怎么做才能让它找到 Express 的类型定义? 这是我写的代码:

///<reference path="../../node_modules/@types/express/index.d.ts"/>

/**@param {Express} app */
module.exports=function(app){
    app.get('/testRoute',function(req,res){
        res.send('Hi, I\'m just a simple test');
    });
};

【问题讨论】:

    标签: express types visual-studio-code intellisense jsdoc


    【解决方案1】:

    Automatic typings acquisition 应该自动选择那些类型为正常的importrequire 语句,所以一般你不应该再写/// reference path=

    尝试类似:

    import express from 'express';
    
    module.exports = function (/** @type {express.Express} */ app) {
        app.get('/testRoute', function (req, res) {
            res.send('Hi, I\'m just a simple test');
        });
    };
    

    目前在使用require 时存在一个错误,该错误会阻止类型 IntelliSense 正常工作。 This TypeScript issue 跟踪可能的解决方案

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-20
      • 1970-01-01
      • 2018-07-20
      • 2018-01-16
      • 2021-08-15
      • 2017-06-18
      • 2018-07-31
      • 2019-05-15
      相关资源
      最近更新 更多