【发布时间】:2018-07-10 18:51:57
【问题描述】:
我正在处理一个一直在使用类型的项目,我现在需要从 @types 存储库安装一个定义。
我已经安装了 @type 并在我的 node_modules\@types 文件夹中看到它,但我的 TS 编译器没有选择类型。
我们的tsconfig.json如下:
{
"compilerOptions": {
"target": "es5",
"sourceMap": true,
"outDir": "./dist",
"rootDir": "../",
"noImplicitAny": false,
"noImplicitThis": false,
"noUnusedLocals": false,
"noUnusedParameters": false,
"pretty": true,
"removeComments": false,
"allowUnreachableCode": false,
"declaration": false,
"allowJs": true,
"module": "commonjs",
"typeRoots" : ["./typings/index.d.ts", "../../node_modules/@types"],
},
"include": [
"./typings/index.d.ts",
"./app/**/*.module.ts",
"./app/**/*.run.ts",
"./app/**/*.routes.ts",
"./app/**/*.enum.ts",
"./app/**/*.controller.ts",
"./app/**/*.model.ts",
"./app/**/*.directive.ts",
"./app/**/*.component.ts",
"./app/**/*.filter.ts",
"./app/**/*.service.ts",
"./app/interfaces/**/*.ts"
],
"exclude": [
"dist",
"node_modules"
]
}
请注意,我们的 tsconfig 不在项目的根目录下,而是在一个子目录中,如下所示
我为 typeRoots 添加了一个额外的路径,以指向我的 node_modules 目录,但这没有任何区别。
我为其安装了@types 的特定库是传单,其 index.d.ts 的开头行是:
export as namespace L;
当我在我的一个 TS 源文件中键入“L”时,编译器没有找到它。
我一定是做错了什么,是否可以混合使用类型和 @types 存储库中的类型?
最终我们应该转而只使用@types,但我想弄清楚为什么我无法在我的编辑器中检测到这个特定的传单@type(我正在使用 VS Code,以防万一)
【问题讨论】:
标签: typescript typescript-typings typescript2.0