Skip to content
Your logo here
Your logo here
Your logo here
Your logo here
Your logo here
Your logo here
Your logo here
Your logo here
Your logo here
Your logo here
Your logo here
Your logo here
Your logo here
Your logo here
Your logo here
Your logo here
Your logo here
Your logo here

JavaScript Support

allowJs

Allow JavaScript files to be imported inside your project, instead of just .ts and .tsx files. For example, this JS file:

js
// @filename: card.js
export const 
defaultCardDeck
= "Heart";
Try

When imported into a TypeScript file will raise an error:

ts
// @filename: index.ts
import { 
defaultCardDeck
} from "./card";
console
.
log
(
defaultCardDeck
);
Try

Imports fine with allowJs enabled:

ts
// @filename: index.ts
import { 
defaultCardDeck
} from "./card";
console
.
log
(
defaultCardDeck
);
Try

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.

checkJs

Works in tandem with allowJs. When checkJs is enabled then errors are reported in JavaScript files. This is the equivalent of including // @ts-check at the top of all JavaScript files which are included in your project.

For example, this is incorrect JavaScript according to the parseFloat type definition which comes with TypeScript:

js
// parseFloat only takes a string
module.exports.pi = parseFloat(3.142);

When imported into a TypeScript module:

ts
// @filename: constants.js
module
.
exports
.
pi
=
parseFloat
(3.142);
// @filename: index.ts import {
pi
} from "./constants";
console
.
log
(
pi
);
Try

You will not get any errors. However, if you turn on checkJs then you will get error messages from the JavaScript file.

ts
// @filename: constants.js
module
.
exports
.
pi
=
parseFloat
(3.142);
Argument of type 'number' is not assignable to parameter of type 'string'.
// @filename: index.ts import {
pi
} from "./constants";
console
.
log
(
pi
);
Try

maxNodeModuleJsDepth

The maximum dependency depth to search under node_modules and load JavaScript files.

This flag can only be used when allowJs is enabled, and is used if you want to have TypeScript infer types for all of the JavaScript inside your node_modules.

Ideally this should stay at 0 (the default), and d.ts files should be used to explicitly define the shape of modules. However, there are cases where you may want to turn this on at the expense of speed and potential accuracy.