Run TypeScript Natively in Node.js

This ad is not shown to multipass and full ticket holders
JSNation US
JSNation US 2025
November 17 - 20, 2025
New York, US & Online
See JS stars in the US biggest planetarium
Learn More
In partnership with Focus Reactive
Upcoming event
JSNation US 2025
JSNation US 2025
November 17 - 20, 2025. New York, US & Online
Learn more
Bookmark
Rate this content

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

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

FAQ

Node.js has introduced the ability to run TypeScript directly without the need for source maps, using a feature called 'experimental strip types' that removes TypeScript-specific syntax to allow execution.

Challenges include TypeScript's lack of a specification, which can lead to breaking changes with minor updates, and the need for interoperability with ESM modules, which was recently resolved.

Amaro is a custom wrapper around the SWC library, specifically for Node.js, enabling the experimental strip types feature to run TypeScript code without needing source maps.

Enums are not supported in the type stripping feature because they require code transformation that affects runtime, which goes against the goal of type stripping to avoid runtime code generation.

The 'experimental transform types' flag allows for the transformation of TypeScript features that require it, such as enums, but it remains experimental and is not recommended for production use.

Developers should use the TSConfig flags like 'erasable syntax only', 'verbatim module syntax', and 'rewrite relative import extensions' to ensure compatibility with Node.js type stripping.

While experimental, the integration is stable enough for use, and many companies have adopted it. It is recommended for projects that do not prioritize startup time.

The Node.js team holds regular meetings with the TypeScript team to ensure alignment and support for the integration, addressing potential issues and future updates collaboratively.

Type stripping removes TypeScript-specific syntax from the code, leaving only JavaScript code which can be executed. This process avoids the need for source maps, maintaining code location consistency by replacing removed syntax with blank spaces.

TypeScript was chosen due to its growing popularity and demand, as well as its status as a widely adopted JavaScript superset, unlike CoffeeScript or Flow, which have seen decreasing usage.

Marco Ippolito
Marco Ippolito
28 min
12 Jun, 2025

Comments

Sign in or register to post your comment.
Video Summary and Transcription
Discussion on TypeScript adoption in Node.js, typescript's popularity, challenges in integrating TypeScript with Node.js due to versioning differences, introducing strip types to remove non-JavaScript syntax, leveraging the SWC library through Amaro for efficient code execution, Node.js support for TypeScript with experimental strip types, enabling transform types and source maps by default, TypeScript evolution with new flags for type checking, TypeScript ESM code evaluation in Node, issues with TypeScript and JavaScript syntax ambiguity, collaboration between Node.js and TypeScript teams, recommendations on using TypeStripping for production projects, comparison of performance between TS Node and Node for TypeScripting, handling type definitions and runtime checking in TypeScript using Zod.

1. Analyzing TypeScript Support in Node.js

Short description:

Discussion on TypeScript adoption in Node.js, TypeScript's popularity, and challenges in integrating TypeScript with Node.js due to versioning differences.

Yeah, so today we will talk about how we made it possible to run TypeScript directly in Node.js and why, and why not maybe CoffeeScript or Flow, or like, why TypeScript? So it doesn't matter. So let's start from the beginning. So if you were at the keynote today, we talked about the state of JS. And I have a very cool piece of history for you. This is the State of JS 2016 prehistoric. And we can see TypeScript was just at the beginning. We can see CoffeeScript and ClosureScript, a lot of technologies that were much popular than TypeScript, but then disappeared.

TypeScript has won the battle of the JavaScript superset. It is considered one of the most popular programming languages according to GitHub. It's on the rise. And JavaScript is going a little bit down. And also is one of the fastest growing languages in 2024. So if you come on the Node.js repo, open an issue, why don't you support CoffeeScript or Flow? This is the reason why. Because people did that. So it was fun.

As a Node.js project, we had a lot of issues. Please support TypeScript. Please, we want TypeScript. We want to be able to run Node.file.js, whatever. So there were years of discussions, years of like how we can do that. So there are a few challenges to this TypeScript support. The first one is that TypeScript does not have a spec. TypeScript is the implementation is the spec. And it does not follow SEMVer. So whenever it releases a new minor, it can have breaking changes. And that's a problem because Node.js has very strict stability guarantees. A Node.js release lasts about three years, while TypeScript moves much, much faster. So taking TypeScript as a library, putting inside Node, yeah, it's easy. But it's not what you want. You don't want breaking changes every three months.

2. Challenges with TypeScript Integration in Node.js

Short description:

Discussing challenges with TypeScript integration in Node.js, overcoming the source map requirement, and the introduction of strip types for TypeScript in Node.js.

Like you have your deploy breaking on a Friday. You don't want that. So that's why we could not take TypeScript as a library directly and put it into Node. Another issue was that until this year, when we released the required ESM in all the Node.js release lines, the interoperability was still an issue, was problematic. Now that issue has been solved so you can require ESM modules. And they are fully interoperable.

TypeScript requires source map or maybe that's what we thought, that TypeScript requires source map. This is not completely true because we found a way to run TypeScript without source map. But people were not happy about having source map because they are a huge performance penalty. They are prone to bugs. It's very hard to implement them correctly. And finally, no champion. Nobody wanted to do the work of implementing it, especially as a volunteer.

This was a lot of work. But one morning last year, I woke up and I opened this PR, which is the most upvoted PR in the Node repo. And it's add experimental strip types. So this was the first piece of running TypeScript natively in Node.js. So I did it just because I felt it. Like, no real reason. I just wanted to prove that it was possible to run TypeScript in Node. And this PR landed in 20 days, which was incredible at the time.

QnA

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.