在一个文件中引用typescript定义,而不是所有JS文件? [英] Reference typescript definitions in one file, instead of all JS files?

查看:48
本文介绍了在一个文件中引用typescript定义,而不是所有JS文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆