How TypeScript Is Evolving to Run More Like JavaScript
TypeScript is well-known as a superset of JavaScript, meaning every valid JavaScript code is also valid TypeScript. Most of the time, TypeScript adds type annotations and other features that help developers catch errors early. But there’s a new development that could make working with TypeScript even smoother—something called type stripping.
What Is Type Stripping and How Does It Work?
Type stripping is the process of removing all TypeScript-specific syntax from a program to turn it into plain JavaScript. Interestingly, in many cases, you can go through a TypeScript program, delete all the type information, and end up with valid JavaScript. This idea isn’t entirely new; it’s similar to Java’s type erasure, where type info is discarded at runtime.
Recently, the Node.js runtime introduced a feature that makes this process easier. Starting with Node version 22.6, you can run TypeScript files directly without a separate compilation step, thanks to the –experimental-strip-types flag. When used, this flag strips out all the TypeScript code that isn’t compatible with JavaScript, making the file ready to run immediately.
This feature allows developers to run TypeScript code more directly, which can speed up workflows and reduce complexity. Modern JavaScript engines like Deno and Bun have supported similar capabilities for some time, but Node’s implementation is gaining mainstream attention, especially in enterprise environments.
How Does Type Stripping in Node.js Work?
To see how it works, consider a simple TypeScript program that defines an interface and a function:
// animal.ts interface Animal { name: string; winged: boolean; } function move(creature: Animal): string { if (creature.winged) { return `${creature.name} takes flight.`; } return `${creature.name} walks the path.`; } const bat: Animal = { name: “Bat”, winged: true }; console.log(move(bat));
If you try to run this in Node with a regular command, you’ll get a syntax error because Node doesn’t understand TypeScript syntax like interfaces:
$ node animal.ts
C:\Users\matth\node\animal.ts:1 interface Animal { ^^^^^^ SyntaxError: Unexpected identifier ‘Animal’
But if you run the same file with the –experimental-strip-types flag, it works perfectly:
$ node –experimental-strip-types animal.ts
Bat takes flight.
This flag strips out all TypeScript-specific parts, leaving only plain JavaScript. For example, the interface and type annotations are removed. What remains is a JavaScript function and an object that can run without issues.
This capability has been influential enough that the TypeScript team added a new flag called erasableSyntaxOnly in version 5.8, making this feature part of the language’s core design. The idea is to make TypeScript more flexible and easier to use in various environments, especially at runtime.
What Are the Broader Impacts of This Change?
One of the biggest benefits of type stripping is better debugging. When types are removed, developers want the line numbers in error messages to match the original code. To make this possible, whitespace is preserved during stripping, so the code structure stays intact. This way, debugging becomes less confusing, and developers can trace errors more easily.
In the past, stripping types often meant losing valuable debug information, making it harder to troubleshoot issues. Now, with whitespace preserved, the experience improves significantly. It also means that source maps—the tools that connect compiled code back to the original source—can work more effectively, giving developers better insights without extra setup.
Overall, these enhancements make TypeScript more adaptable, allowing developers to build faster, debug more easily, and run code in environments that previously required separate compilation steps. As runtime support for type stripping grows, it could change how TypeScript is used in production, making it more seamless and integrated into the JavaScript ecosystem.












What do you think?
It is nice to know your opinion. Leave a comment.