如何生成由VS代码自动拾取的TypeScript定义文件?
我有一个在Node.js中使用的TypeScript项目,我决定添加types定义,以便IntelliSense可以在Visual Studio代码中进行提取。 在我的tsconfig.json
,我已经启用了与编译后的JS一起生成的定义,但是我不知道我需要做什么其他设置,以便在使用npm下载我的项目时,这些types出现在IntelliSense中,而没有其他的build立。 任何人有任何想法如何做到这一点? 我的tsconfig.json
文件:
{ "compilerOptions": { "target": "es5", "lib":["es2016","es2016.array.include","dom"], "noImplicitAny":false, "noEmitOnError":true, "removeComments": true, "declaration": true }, "include": [ "src/ts/**/*" ], "exclude": [ "node_modules", "**/*.spec.ts" ] }
在你的package.json
文件中设置types
属性来指向你的定义文件,就像这样(假设你的声明在src/ts/main.d.ts
):
{ "types": "./src/ts/main.d.ts" }
有关详细信息,请参阅TypeScript文档 。