TSConfig
allowJs
Allow JavaScript files to be imported inside your project, instead of just .ts and .tsx files. For example, this JS file:
jsTry// @filename: card.jsexport constdefaultCardDeck = "Heart";
When imported into a TypeScript file will raise an error:
tsTry// @filename: index.tsimport {defaultCardDeck } from "./card";console .log (defaultCardDeck );
Imports fine with allowJs enabled:
tsTry// @filename: index.tsimport {defaultCardDeck } from "./card";console .log (defaultCardDeck );
This flag can be used as a way to incrementally add TypeScript files into JS projects by allowing the .ts and .tsx files to live along-side existing JavaScript files.
It can also be used along-side declaration and emitDeclarationOnly to create declarations for JS files.