在一个文件中引用typescript定义,而不是所有JS文件? [英] Reference typescript definitions in one file, instead of all JS files?
问题描述
我正在使用Visual Studio Code中的Node JS(+ Express)项目,我想知道是否有一种方法可以在一个全局位置引用TypeScript定义,而不必在每个JS文件中重新引用定义。
I'm working on a Node JS (+Express) project in Visual Studio Code, and am wondering if there is a way to reference TypeScript definitions in one global spot, rather than having to re-reference definitions in every JS file.
我看到VSCode支持tsconfigs,但我不认为.tsconfig文件有一个部分。
I see that VSCode supports tsconfigs, but I don't think .tsconfig files have a section for that.
推荐答案
在某些编辑器中,您可以使用tsconfig.json中的 filesGlob
属性来简化引用。
In some editors you can use the filesGlob
property in tsconfig.json to simplify references.
例如:
"filesGlob": [
"./scripts/*.ts",
"!./node_modules/**/*.ts"
]
但是,仅当TypeScript 2发布时,这将适用于TypeScript编译器(参见 globs ):
However, this will work with the TypeScript compiler only when TypeScript 2 is released (see globs):
或者您可以指定单个文件
:
"files": [
"./scripts/app.ts",
"./scripts/other.d.ts"
]
这篇关于在一个文件中引用typescript定义,而不是所有JS文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!