Joseph Humfrey
Joseph Humfrey

Reputation: 3054

How to use @ts-check in VS Code across multiple files with non-module-based website?

I'm trying to create a really simple website with:

BUT I'd love to be able to use TypeScript's @ts-check or jsconfig.json within VS Code, and for it to understand the global scope of the code across JavaScript files. However, I'm finding that it's unable to jump to definitions between JavaScript files (or at least, inconsistently?).

Is there a way to tell the TypeScript compiler that all the JavaScript files are in global scope together, and to use the correct order of evaluation from the index.html?

Upvotes: 5

Views: 2200

Answers (1)

myf
myf

Reputation: 11313

Use "js/ts.implicitProjectConfig.checkJs": true in VSC config (or // @ts-check in files) and reference other files with /// <reference path="[...]" />

/// <reference path="other.js" />

somethingDefinedInOtherJS; // no error, f12 go to definition works

See Triple-Slash Directives docs for TS for more info.

Upvotes: 6

Related Questions