Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference typescript definitions in one file, instead of all JS files?

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.

I see that VSCode supports tsconfigs, but I don't think .tsconfig files have a section for that.

like image 323
russjr08 Avatar asked Apr 30 '15 18:04

russjr08


2 Answers

In some editors you can use the filesGlob property in tsconfig.json to simplify references.

For example:

"filesGlob": [
    "./scripts/*.ts",
    "!./node_modules/**/*.ts"
]

However, this will work with the TypeScript compiler only when TypeScript 2 is released (see globs):

Or you can specify individual files:

"files": [
    "./scripts/app.ts",
    "./scripts/other.d.ts"
]
like image 51
Fenton Avatar answered Oct 16 '22 14:10

Fenton


Okay so after a couple of restarts with Code, it seems that most of the time it will pick up the typescript definitions that you've included in other files.

I think I'll still go with Steve's answer though, as that way I can avoid having a bunch of references in my code.

like image 24
russjr08 Avatar answered Oct 16 '22 15:10

russjr08