Configure, migrate, and verify projects
How to Migrate a JavaScript Project to TypeScript One File at a Time
Migrate JavaScript to TypeScript file by file with allowJs, per-file JSDoc checks, separate compiler output, and build and test verification.

You do not need to rename an entire application to start a TypeScript migration. Let the compiler read the existing JavaScript alongside converted TypeScript, then move manageable files or batches across. After each batch, check the compiler's input, the project's build, and the relevant tests. Those paths may not use the same settings.
Include JavaScript without writing over it
This tsconfig.json follows the TypeScript migration handbook's emitting configuration. It assumes this example project's inputs live under src/:
{
"compilerOptions": {
"outDir": "./built",
"allowJs": true,
"checkJs": false,
"target": "es5",
"noImplicitAny": true
},
"include": ["./src/**/*"]
}
include selects the source tree, allowJs accepts JavaScript inputs, and outDir keeps emitted files away from the originals. The es5 target is a choice for this example, not a migration requirement. Choose an output target and any module settings for the repository's actual build and runtime. In particular, do not assume this compiler configuration can replace an existing bundler or that an existing build will accept renamed files without changes.
Here, checkJs remains false so the team can opt individual JavaScript files into checking. Enabling noImplicitAny early is a deliberate choice: if that check is part of the intended end state, converted files should surface missing parameter types as they arrive, rather than in a later cleanup pass. It may mean smaller batches are practical.
Pick a file whose edges you know
Start with a file whose callers and dependencies you understand, rather than renaming the entire tree or choosing a central entry point first. Schedule a small number of files during ordinary work, adjusting the batch to the project's size and the issues each file exposes. In one team's account, developers migrated a few files each sprint. That describes their cadence, not a rate every team should expect.
Before renaming src/discount.js, you can opt that one file into checking and write down its parameter and return types with JSDoc:
// @ts-check
/**
* @param {number} price
* @param {number} percentage
* @returns {number}
*/
export function calculateDiscount(price, percentage) {
return price - (price * percentage) / 100;
}
The per-file @ts-check approach lets you investigate that file's reported issues without turning on checks for every remaining JavaScript file. Its JSDoc describes a contract for checking; it does not validate values when the function runs.
Rename, then address the types it exposes
Rename src/discount.js to src/discount.ts and express the same contract in TypeScript:
export function calculateDiscount(
price: number,
percentage: number
): number {
return price - (price * percentage) / 100;
}
The migration handbook uses .ts for an ordinary JavaScript file and .tsx for one containing JSX. A rename can expose questions about parameters, returns, imports, and shared shapes. Resolve the relevant type errors rather than adding any solely to silence them. If a package's declarations are missing, check whether its corresponding @types package is available; the TypeScript documentation gives @types/lodash as an example.
Converted and unconverted files can remain neighbors. For example, an unconverted src/checkout.js can call the renamed function:
// src/checkout.js
import { calculateDiscount } from "./discount";
export function checkoutTotal(price, percentage) {
return calculateDiscount(price, percentage);
}
This extensionless import is an example for a project whose build accepts that import form. Check the repository's module resolution and build behavior before copying it. If several JavaScript files need a shape already defined in TypeScript, a JSDoc import() type reference can avoid writing the shape twice:
// @ts-check
/**
* @param {import("./types").Order} order
* @returns {string}
*/
export function describeOrder(order) {
return `Order ${order.id}: $${order.total}`;
}
Use that optional pattern only where the referenced Order type exists and the import resolves in the project's setup.
Verify the batch through its separate paths
These commands are placeholders for a repository with tsc available and existing build and test npm scripts. Adjust command names and module settings to its toolchain:
tsc -p tsconfig.json
npm run build
npm test
First, confirm that the compiler includes the intended JavaScript and TypeScript files. Look for the checks expected from an opted-in JavaScript file, or address relevant errors in the renamed TypeScript file. With the configuration above, compiler output belongs in built/, not beside the source inputs. If emitting despite type errors is unacceptable for this path, consider the documented noEmitOnError option and verify its effect in the repository.
Next, run the established build to find out whether its configured path accepts the changed extensions and imports. Run relevant tests to check the behavior they exercise. Neither result establishes that every runtime path works. In one reported migration, Webpack and Mocha used different compilation paths, and an import failed at runtime in tests. If build and test results disagree, inspect each tool's import handling and compilation settings before making a project-wide import change. A clean type check, a completed build, and passing tests answer different questions; keep all three visible as the next file enters the queue.



