【问题标题】:how to use mongoose typings with angular 2 webpack starter如何在 angular 2 webpack starter 中使用猫鼬类型
【发布时间】:2017-06-21 16:22:40
【问题描述】:

我是新手,所以应该很简单。

我正在使用angular2-webpack-starter

根据mongoose docs,如果我包含他们的 js 文件,我可以获得 mongoose 的全局变量

如果我做declare var mongoose : any; 工作,但我想要猫鼬的打字。我似乎不知道如何添加这些。

当我执行npm install @types/mongoose -S 后,我可以看到文件node_mudles/mongoose/index.d.ts 我如何告诉typescripte 变量mongoose 是该文件中的一个类型?

提前致谢。

【问题讨论】:

    标签: angular typescript mongoose webpack typing


    【解决方案1】:

    安装mongoose@types/mongoose 后,只需导入即可。

    查看here

    import * as mongoose from 'mongoose';
    

    另外,请确保您在tsconfig.json 中的compilerOptions 中设置了以下内容。

     "typeRoots": [
          "node_modules/@types"
        ]
    

    【讨论】:

      猜你喜欢
      • 2017-01-08
      • 2017-05-11
      • 2018-01-06
      • 2019-01-24
      • 1970-01-01
      • 2021-10-07
      • 1970-01-01
      • 2019-12-17
      • 2021-09-26
      相关资源
      最近更新 更多