Advertisement
Beginner TypeScript, Migrating JavaScript to TypeScript

What does the 'allowJs' compiler option do, and why is it useful during migration?

Short answer

allowJs lets the TypeScript compiler process plain .js files alongside .ts files in the same project, so you can incrementally rename files to .ts one at a time while the rest of the codebase remains JavaScript and still compiles/type-checks together.

Save TypeScript mock interview
Advertisement
AModel answer
allowJs lets the TypeScript compiler process plain .js files alongside .ts files in the same project, so you can incrementally rename files to .ts one at a time while the rest of the codebase remains JavaScript and still compiles/type-checks together.
// tsconfig.json
{
  "compilerOptions": { "allowJs": true }
}
// Both utils.js and newFeature.ts can coexist and be imported from each other
Real-world example
Allowing a new feature to be written in TypeScript from day one while the surrounding legacy code stays in plain JavaScript.
Likely follow-ups
  • What's the difference between 'allowJs' and 'checkJs'?
Related topics