Node's getting TypeScript support
Node is getting get the ability to run TypeScript files, behind a CLI flag for now.
Types are straight up removed
It does so by first removing type annotations. Then Node can run the left-over JavaScript.
Several commenters commented that this is already possible in a couple different ways
Compile to JS and run that
Specify a loader
Use tsx or ts-node
But these all need set up and configuration.
The pull request author, Marco Ippolito, points out:
I believe enabling users to execute TypeScript files is crucial to move the ecosystem forward, it has been requested on all the surveys, and it simply cannot be ignored. We must acknowledge users want to run
node foo.ts
without installing external dependencies or loaders.
Adding this support is one less reason for someone to choose Deno or Bun.
Just a subset of TypeScript for now
There's still discussion about supporting all of TypeScript. For now, though, you'll only be able to use TypeScript features that have no run-time impact.
The good thing is, this is most of TypeScript! What you can't use right now are (mostly) enums1 and decorators.
There are a couple reasons this is currently limited to a subset
It doesn't matter so much what version of TypeScript you're using. The types are just removed.
It's simpler and easier to implement.
Commenters had a lot of concerns about not supporting all TS features. Folks from the TypeScript team even talked about the potential for confusion, and the pain that could cause with such a massive user base.
Where the team ended up, though, is Node directly handles basic use cases. More advanced features require some setup.
No TS in published packages, yet
Even though you'll be able to run TS files, you won't see TS in packages published to npm. Not yet, anyway.
This is because once TS packages in the wild, the genie is out of the bottle. There’s no removing TS support at that point.
I doubt TS support will be removed, but it is experimental and makes sense to be able to remove the experiment if things go horribly awry.
Web Assembly for a simpler toolchain
To actually remove types, Node uses a library called @swc/wasm-typescript. Well, actually a wrapper of it called amaro.
One thing you'll notice from the name is it's Web Assembly. Not so much for performance2, but because Node can already run Web Assembly. There's no need to bring in Go or Rust into the toolchain, which keeps thing simpler.
Another thing stood out: the author of swc put a lot of time into helping out the Node effort. For example, by cutting several releases with features that Node needed.
File extensions were brought up a lot
I was surprised by one complaint that came up several times. Importing a TS file from a non-existent .js file.
File extensions are required in Node because of how ES modules work. So far so good. But I guess TypeScript used to recommend writing a .js extension for a .ts file.
// There is Cats.ts, but no Cats.js.
import Cat from './Cat.js';
Very interesting. As someone who's never done or seen that, it seems needlessly confusing.
In any case, doing this was rejected by the Node team. Node won't have to guess at what the real file path is.
There were a lot of questions, thoughts, and feelings about this in comments, though.
What about the TC39 type annotations proposal
Another thing came up again and again - the TC39 type annotations proposal.
It may one day be part of the JS specification. So a common suggestion was Node should support it, not TypeScript per se.
There are a couple reasons to not target the type annotations proposal for now, though
TypeScript is what users are asking to run
The type annotations proposal is only in stage 1
If you're not familiar with the TC39 stages, stage 1 is early in the process and "under consideration". Likely it's years away from shipping, and not even fully formed yet.
One of my favorite lines from the PR is
I'm not gonna let this [get] bogged down by a Stage 1 proposal
What kind of bike shed do you want?
Kudos to Marcos for implementing and shipping this PR. As I'd expect, everyone had an opinion on everything in it. Throughout he was professional and respectful, while keeping things moving forward.
It'll be great having the option to run TS files from Node one day. I have several scripts at work that could benefit.
Experimental TS support landed in a v23 nightly release, so expect to use it in Node 24 (due at the end of 2025).
TypeScript doesn’t really want you to use Enums, anyway. See https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums
Although performance is probably part of it.