Hi Folks! How have you been doing? Everything ok? I hope so!
And with this title, I will ask you? Clickbait or not?
The answer is NO!!!!
YEAAHH! FINALLY it will going support typescript, not yet, but the typescript in Node initiative started!
But first, I'm going how begins initiative. First, the TC39
repository of Ecmascript organization created the repository ECMAScript proposal: Type Annotations
. As the title of repository represents, the Ecmascript started the discussion and the propposal.
On README of the project:
This proposal aims to enable developers to add type annotations to their JavaScript code, allowing those annotations to be checked by a type checker that is external to JavaScript. At runtime, a JavaScript engine ignores them, treating the types as comments.
The aim of this proposal is to enable developers to run programs written in TypeScript, Flow, and other static typing supersets of JavaScript without any need for transpilation, if they stick within a certain reasonably large subset of the language.
And the key word is Transpilation
!
If you dont't know Bun or Deno supports typescript. But Node wants to create something native. When we write code in typescript, the browser or node, transpile to Javascript and after that the code is compiled.
So Node wants to skip the transpilation step.
How the Typescript Actually Works:
And after the State of JS research of the community, what they most feels missing on JS:
So read the Github of TC39: https://github.com/tc39/proposal-type-annotations
Initiative Node With Typescript
Now let's talk about this amazing point of change of node!
This PR was opened bringing the initiative on Node: https://github.com/nodejs/node/pull/53725
AND IT WAS MERGED!
To compile the Typescript it was used SWC:
SWC is an extensible Rust-based platform for the next generation of fast developer tools. It's used by tools like Next.js, Parcel, and Deno, as well as companies like Vercel, ByteDance, Tencent, Shopify, and more.
SWC can be used for both compilation and bundling. For compilation, it takes JavaScript / TypeScript files using modern JavaScript features and outputs valid code that is supported by all major browsers.
SWC is based on Rust and it will used to compile the typecript on Node.
@swc/wasm-typescript its a small package with a wasm and a js file to bind it.
Swc is currently used by Deno for the same purpose, it's battle tested.
In the future I see this being implemented in native layer.
So in the next releases of Node, propably we will have the flag: --experimental-strip-types
So running with
node index.ts --experimental-strip-types
Probably we can use typescript nativally, without to config the typescript and files like tsconfig.json
.
Let's see the next chapters of releases of node 👀
Annnd just to finish, I contribute with the PR: https://github.com/nodejs/node/pull/54107
Just to validate some features of typescript on node repository, adding tests.
So that's it, lovely people!
I hope you liked of this news and I hope to bring news for you about the progress of the initiative soon with the next release of the node.
Thank you so much and stay well, always!
Contacts:
Linkedin: https://www.linkedin.com/in/kevin-uehara/
Instagram: https://www.instagram.com/uehara_kevin/
Twitter: https://x.com/ueharaDev
Github: https://github.com/kevinuehara
dev.to: https://dev.to/kevin-uehara
Youtube: https://www.youtube.com/@ueharakevin/
Top comments (3)
I loved your article. And to be honest, I'm surprised with node team to add this feature and be better than deno and bun skipping the transpilation part.
Yeah!!! I'm also very surprised. One curiosity that is in the future they don't want to import using
ts
extension for example hahah. Example:This is a wonderful news! I really hope that. Native typescript is my dream!