The Path to Native TypeScript

Bookmark
Rate this content

Imagine the convenience of executing TypeScript files directly with Node.js. Just a few years ago, this concept seemed like a distant dream. Today, it stands as an exciting experimental feature. This narrative dives into the journey of transforming this dream into a reality.

This talk has been presented at Node Congress 2025, check out the latest edition of this JavaScript Conference.

FAQ

Existing TypeScript code can be made compatible using a code mode called correct-yes-specifiers to transform unsupported imports into supported ones.

Marco Ippolito is a senior security engineer at Herodas and a member of the Node.js Technical Steering Committee.

TypeStripping is a method to integrate TypeScript into Node.js by only performing transpilation, removing everything from TypeScript that is not JavaScript, and avoiding type checking.

TypeScript was not integrated earlier due to challenges in reaching consensus in the open governance of Node.js, differences in stability guarantees between Node.js and TypeScript, and the lack of a champion to lead the integration efforts.

Challenges include differing stability guarantees, the lack of Node.js support for configuration files like TSConfig, the large size of TypeScript as an NPM package, and issues with CommonJS and ESM interoperability.

TypeStripping avoids the need for source maps by replacing removed TypeScript inline types with whitespace, preserving the original code location.

Limitations include the inability to support features requiring transformation like namespaces and enums, no support for custom paths requiring TSConfig, and the requirement to specify file extensions explicitly.

The experimental transform types flag allows the use of all TypeScript syntax, including namespaces and enums, by enabling source maps.

Node.js attempts to evaluate syntax as common JS, and ESM, and then strips types if necessary. It may use the input type flag to directly specify the syntax type, reducing overhead.

The erasable syntax-only flag in TypeScript ensures that all syntax is supported by Node.js, throwing errors for unsupported syntax during type-checking.

Marco Ippolito
Marco Ippolito
24 min
17 Apr, 2025

Comments

Sign in or register to post your comment.
  • Va Da
    Va Da
    P4
    TypeScript is the future, adoption looks great.
Video Summary and Transcription
Today's Talk discusses the integration of TypeScript in Node.js. The path to native TypeScript in Node.js is explored, including the history of user requests for native support. Implementing TypeScript in Node.js poses challenges due to differences in stability guarantees and tool compatibility. TypeStripping is a transpilation-focused implementation that removes non-JavaScript features, making it stable across TypeScript versions. The Amaro package, built on SWC, provides compatibility and speed for type stripping. Experimental Strip Types and Transform Types flags enable erasable TypeScript features. TypeScript has limitations such as namespace and enum support in JavaScript and code migration issues. TypeScript Import Types and Syntax Detection are ongoing developments. Ambiguity in syntax between JavaScript and TypeScript is addressed with an erasable syntax only flag. Future steps include bug fixing, performance improvements, and upcoming Node.js releases.

1. Introduction to Native TypeScript in Node.js

Short description:

Today I will talk about the path to native TypeScript, so how Node.js and TypeScript have worked together to bring this new integration into Node.js. TypeScript has gone from being a niche technology to one of the most popular languages in the web development scene. We will also explore why Node.js has only now integrated TypeScript and the history of user requests for native support.

Welcome, everyone. I'm very happy to give this talk here at Node Congress. Today I will talk about the path to native TypeScript, so how Node.js and TypeScript have worked together to bring this new integration into Node.js.

Let me introduce myself. My name is Marco Ippolito. I'm a senior security engineer at Herodas and a member of the Node.js Technical Steering Committee.

So we will start with a little bit of history, so how and why we decided to support TypeScript and what changed in the past few years. So we will start with this chart. This is the state of JS 2016, so almost 10 years ago. And we can see that TypeScript was just at the beginning was not very popular. In fact, 34% of the respondents, they heard of TypeScript, but they were not interested into it. And just a small fraction was actually interested and has used it and would use it again. We can also see a few other names that have disappeared from the web development scene, like CoffeeScript, Elm and ClosureScript, but they were quite popular at the time. And we can see now more recent state of JS, which is the 2023. In this chart, we can see that almost all developers that responded, which are 17,000, they use TypeScript only 32%. And in like only 9% of respondents use JavaScript. So the majority of users use TypeScript in some like different percentages, but they all do. And this is crazy to think that 10 years ago, this was like very niche. And today, like everybody uses TypeScript. It's one of the most popular technologies. This is the Stack Overflow 2023 survey. And we can see that TypeScript is the fifth most popular programming language. So today we will see why Node.js has not integrated it years ago and this happened only now. So another very important data is the NPM downloads. TypeScript has around 12 million downloads per day. It is one of the most downloaded packages on NPM. So we will see today how TypeScript is supported in Node.js.

But let's talk a bit about the history. So as Node.js maintainer, I've always seen issues, discussions, PRs of users wanting native TypeScript support. As you can see, there are multiple issues and like there have been so many proposals on how to implement TypeScript in Node.js, but it never happened until recently.

2. Challenges in Implementing TypeScript in Node.js

Short description:

There are reasons why the implementation of TypeScript in Node.js is not straightforward. Getting consensus among the volunteers and open governance of Node.js is challenging. There are different stability guarantees between Node.js and TypeScript, and Node.js does not support TSConfig. Choosing a tool that works out of the box is difficult due to the large size of the TypeScript package and the past issues with CommonJS and ESM interoperability. Source maps are also necessary for effective debugging but add overhead.

And there are reasons why the implementation is not straightforward. One of the first challenges is that it's very hard to get consensus, Node.js being a project run by volunteers and open governance. It's very hard to make everyone agree on what it means to support TypeScript and how it should be done. There have been past attempts in 2023, there was a discussion at the Collaborator Summit in Bilbao, but the discussion, it eventually bled out. So it didn't happen.

There are different stability guarantees between Node.js and TypeScript. TypeScript does not follow SEMVer. So it means that every minor update has breaking changes while Node.js has strong security guarantees. So there is a new, like an LTS release of Node lasts for three years. So it's not possible to lock in a specific version of TypeScript for three years. And this big difference between the two, between Node and TypeScript makes it hard to integrate it. Node.js does not support a configuration file and therefore does not support TSConfig. Having Node supporting TSConfig, it would be weird. And it's something that would not get consensus because in the first place, Node does not have its own config file. So why would it support the config file of another project or dependency of Node.js, which is the reason why Node does not support TSConfig.

It's very hard to choose a tool that works out of the box. As we said, we cannot use TypeScript as an NPM package. We need to use something else. The reason why we cannot use TypeScript is because it's a very large NPM package. It's a 24 megabyte package. It's written in JavaScript and it would be very hard to integrate and not to mention the stability guarantees that we talked about before. So like there is not a single tool that fits the use case of Node and therefore it's very hard to choose. In the past, there were a lot of issues between CommonJS and ESM interoperability. So until those were fixed, it would have been a half-baked feature to integrate TypeScript. But now those are finally fixed. And so we had a chance to support TypeScript. Source maps. So whenever you transpile your code, you change the position of your code inside file by transforming TypeScript into JavaScript. So you would need source maps to be able to debug effectively and to reconstruct the location of everything in your source code. But source maps add a lot of overhead.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

React's Most Useful Types
React Day Berlin 2023React Day Berlin 2023
21 min
React's Most Useful Types
Top Content
Watch video: React's Most Useful Types
Today's Talk focuses on React's best types and JSX. It covers the types of JSX and React components, including React.fc and React.reactnode. The discussion also explores JSX intrinsic elements and react.component props, highlighting their differences and use cases. The Talk concludes with insights on using React.componentType and passing components, as well as utilizing the react.element ref type for external libraries like React-Select.
TypeScript and React: Secrets of a Happy Marriage
React Advanced 2022React Advanced 2022
21 min
TypeScript and React: Secrets of a Happy Marriage
Top Content
React and TypeScript have a strong relationship, with TypeScript offering benefits like better type checking and contract enforcement. Failing early and failing hard is important in software development to catch errors and debug effectively. TypeScript provides early detection of errors and ensures data accuracy in components and hooks. It offers superior type safety but can become complex as the codebase grows. Using union types in props can resolve errors and address dependencies. Dynamic communication and type contracts can be achieved through generics. Understanding React's built-in types and hooks like useState and useRef is crucial for leveraging their functionality.
It's a Jungle Out There: What's Really Going on Inside Your Node_Modules Folder
Node Congress 2022Node Congress 2022
26 min
It's a Jungle Out There: What's Really Going on Inside Your Node_Modules Folder
Top Content
The talk discusses the importance of supply chain security in the open source ecosystem, highlighting the risks of relying on open source code without proper code review. It explores the trend of supply chain attacks and the need for a new approach to detect and block malicious dependencies. The talk also introduces Socket, a tool that assesses the security of packages and provides automation and analysis to protect against malware and supply chain attacks. It emphasizes the need to prioritize security in software development and offers insights into potential solutions such as realms and Deno's command line flags.
Making Magic: Building a TypeScript-First Framework
TypeScript Congress 2023TypeScript Congress 2023
31 min
Making Magic: Building a TypeScript-First Framework
Top Content
Daniel Rowe discusses building a TypeScript-first framework at TypeScript Congress and shares his involvement in various projects. Nuxt is a progressive framework built on Vue.js, aiming to reduce friction and distraction for developers. It leverages TypeScript for inference and aims to be the source of truth for projects. Nuxt provides type safety and extensibility through integration with TypeScript. Migrating to TypeScript offers long-term maintenance benefits and can uncover hidden bugs. Nuxt focuses on improving existing tools and finds inspiration in frameworks like TRPC.
ESM Loaders: Enhancing Module Loading in Node.js
JSNation 2023JSNation 2023
22 min
ESM Loaders: Enhancing Module Loading in Node.js
Top Content
ESM Loaders enhance module loading in Node.js by resolving URLs and reading files from the disk. Module loaders can override modules and change how they are found. Enhancing the loading phase involves loading directly from HTTP and loading TypeScript code without building it. The loader in the module URL handles URL resolution and uses fetch to fetch the source code. Loaders can be chained together to load from different sources, transform source code, and resolve URLs differently. The future of module loading enhancements is promising and simple to use.
Towards a Standard Library for JavaScript Runtimes
Node Congress 2022Node Congress 2022
34 min
Towards a Standard Library for JavaScript Runtimes
Top Content
There is a need for a standard library of APIs for JavaScript runtimes, as there are currently multiple ways to perform fundamental tasks like base64 encoding. JavaScript runtimes have historically lacked a standard library, causing friction and difficulty for developers. The idea of a small core has both benefits and drawbacks, with some runtimes abusing it to limit innovation. There is a misalignment between Node and web browsers in terms of functionality and API standards. The proposal is to involve browser developers in conversations about API standardization and to create a common standard library for JavaScript runtimes.

Workshops on related topic

React, TypeScript, and TDD
React Advanced 2021React Advanced 2021
174 min
React, TypeScript, and TDD
Top Content
Featured Workshop
Paul Everitt
Paul Everitt
ReactJS is wildly popular and thus wildly supported. TypeScript is increasingly popular, and thus increasingly supported.

The two together? Not as much. Given that they both change quickly, it's hard to find accurate learning materials.

React+TypeScript, with JetBrains IDEs? That three-part combination is the topic of this series. We'll show a little about a lot. Meaning, the key steps to getting productive, in the IDE, for React projects using TypeScript. Along the way we'll show test-driven development and emphasize tips-and-tricks in the IDE.
Mastering advanced concepts in TypeScript
React Summit US 2023React Summit US 2023
132 min
Mastering advanced concepts in TypeScript
Top Content
Featured WorkshopFree
Jiri Lojda
Jiri Lojda
TypeScript is not just types and interfaces. Join this workshop to master more advanced features of TypeScript that will make your code bullet-proof. We will cover conditional types and infer notation, template strings and how to map over union types and object/array properties. Each topic will be demonstrated on a sample application that was written with basic types or no types at all and we will together improve the code so you get more familiar with each feature and can bring this new knowledge directly into your projects.
You will learn:- - What are conditional types and infer notation- What are template strings- How to map over union types and object/array properties.
Deep TypeScript Tips & Tricks
Node Congress 2024Node Congress 2024
83 min
Deep TypeScript Tips & Tricks
Top Content
Featured Workshop
Josh Goldberg
Josh Goldberg
TypeScript has a powerful type system with all sorts of fancy features for representing wild and wacky JavaScript states. But the syntax to do so isn't always straightforward, and the error messages aren't always precise in telling you what's wrong. Let's dive into how many of TypeScript's more powerful features really work, what kinds of real-world problems they solve, and how to wrestle the type system into submission so you can write truly excellent TypeScript code.
Best Practices and Advanced TypeScript Tips for React Developers
React Advanced 2022React Advanced 2022
148 min
Best Practices and Advanced TypeScript Tips for React Developers
Top Content
Featured Workshop
Maurice de Beijer
Maurice de Beijer
Are you a React developer trying to get the most benefits from TypeScript? Then this is the workshop for you.In this interactive workshop, we will start at the basics and examine the pros and cons of different ways you can declare React components using TypeScript. After that we will move to more advanced concepts where we will go beyond the strict setting of TypeScript. You will learn when to use types like any, unknown and never. We will explore the use of type predicates, guards and exhaustive checking. You will learn about the built-in mapped types as well as how to create your own new type map utilities. And we will start programming in the TypeScript type system using conditional types and type inferring.
Node.js Masterclass
Node Congress 2023Node Congress 2023
109 min
Node.js Masterclass
Top Content
Workshop
Matteo Collina
Matteo Collina
Have you ever struggled with designing and structuring your Node.js applications? Building applications that are well organised, testable and extendable is not always easy. It can often turn out to be a lot more complicated than you expect it to be. In this live event Matteo will show you how he builds Node.js applications from scratch. You’ll learn how he approaches application design, and the philosophies that he applies to create modular, maintainable and effective applications.

Level: intermediate
Build and Deploy a Backend With Fastify & Platformatic
JSNation 2023JSNation 2023
104 min
Build and Deploy a Backend With Fastify & Platformatic
Top Content
WorkshopFree
Matteo Collina
Matteo Collina
Platformatic allows you to rapidly develop GraphQL and REST APIs with minimal effort. The best part is that it also allows you to unleash the full potential of Node.js and Fastify whenever you need to. You can fully customise a Platformatic application by writing your own additional features and plugins. In the workshop, we’ll cover both our Open Source modules and our Cloud offering:- Platformatic OSS (open-source software) — Tools and libraries for rapidly building robust applications with Node.js (https://oss.platformatic.dev/).- Platformatic Cloud (currently in beta) — Our hosting platform that includes features such as preview apps, built-in metrics and integration with your Git flow (https://platformatic.dev/). 
In this workshop you'll learn how to develop APIs with Fastify and deploy them to the Platformatic Cloud.