8

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.

2
  • 1
    Generally external tools which only use tsc require that you include a reference at the top of every file. Visual Studio has a feature which does this automatically, but I'm not sure if this is included in "Code" Commented Apr 30, 2015 at 18:17
  • see answer: stackoverflow.com/a/40861142/187650 Commented Nov 29, 2016 at 8:37

2 Answers 2

9

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"
]
Sign up to request clarification or add additional context in comments.

4 Comments

I did not know about this. I need to put this into IntelliJ right now. Thanks!
It appears Visual Studio Code does support a tsconfig.json file. blogs.msdn.com/b/typescript/archive/2015/04/30/…
Yes - but not filesGlob yet, so you have to specify files instead.
if you leave files undefined (or omit it) then all files are included. much easier if you want them all, until globs are included
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.