NodeJS adding experimental support for Typescript Code Execution
We take a quick look and brief at the experiment support for Typescript files in the latest version of Node JS (v22)
One thing that set both Deno and Bun apart from Node was their ability to run Typescript files directly. This is because the type annotations aren’t part of Javascript. syntax, meaning they would throw a syntax error.
You needed to transpile the Typescript file to Javascript or use something like ts-node to do that for you. For instance, below, I am using the tsc compiler to transpile to Javascript.
But as you can see, this can be tedious compared to something like Bun, which will execute Typescript directly.
NodeJS is adding experiment support for stripping type from Typescript files so that we can execute the Typescript code. NodeJS is introducing two new experimental flags; the first is for stripping Typescript types and is called --experimental-strip-types
.
The second one is --experimental-transform-types
which is to transform typescript types for types such as enums that need to be converted to Javascript equivalent.
Please note that the above is still experimental but a step in the right direction.
Awesome 👏 expected since typescript version 1 LOL 😂
Yeah, should have come sooner