ยท new features

Node.js rolls out experimental TypeScript support

Node.js introduces `--experimental-strip-types` flag to run TypeScript files directly without transpiling, speeding up development. This sounds great but it currently leads to compatibility issues and lack of TypeScript features. The community is discussing concerns and potential solutions for the future.

The --experimental-strip-types flag in Node.js v23.0.0-nightly lets you run TypeScript files directly by stripping out type annotations at runtime. This experimental feature streamlines development by removing the need for a build step.

Why Use It?

Running TypeScript without transpiling speeds up your workflow and makes rapid prototyping possible. No more waiting for buildsโ€”just write and run. This feature might be inspired by Deno, which offers first-class support for TypeScript and thus delivering a better developer experience (DX).

How to Use It

Create a TypeScript File:

function greet(name: string) {
  return `Hello, ${name}!`;
}
 
console.log(greet('World'));

Run it with Node.js:

node --experimental-strip-types example.ts

Risks and Considerations

Using --experimental-strip-types could cause fragmentation in TypeScript, possibly requiring compatibility tables and dividing communities and platforms. Because it skips the TypeScript compiler, you miss out on static type checking, increasing the risk of runtime errors. As this workflow simply removes the types, it is not fully compatible with TypeScript feature set. It only supports features that are compatible with JavaScript which makes it not very valuable for most TypeScript projects. Type assertions using as or angle-bracket syntax will be ignored. Enumerations in TypeScript are not processed. Experimental features like decorators, commonly used in frameworks such as Angular, are not supported. TypeScript's namespace declarations are not stripped correctly. Extending modules (module augmentation) with additional types or functionality is not handled.

Community Concerns

Community members have raised additional concerns about the feature:

Grammar Stability: Stripping types from TypeScript without an up-to-date grammar can be problematic because the TypeScript grammar evolves. This evolution may cause parsing issues as new features are added to TypeScript.

Upgrade Issues: Users might need to upgrade Node.js more frequently to stay compatible with the latest TypeScript features, which conflicts with the stability desired from long-term support (LTS) versions of Node.js.

Specific TypeScript Versions: Ensuring that Node.js uses the project-specific version of TypeScript is crucial. Relying on a global TypeScript version can cause compatibility issues with older projects.

The Future

Fortunately, members of the core TypeScript team are actively engaging with the Node.js development team to address related concerns. Their meeting on 24th of July is recorded on YouTube and publicly accessible. Additionally, there's an ongoing TC39 Proposal for Type Annotations, aiming to integrate types natively into JavaScript, which could provide a more unified solution for type safety across JavaScript and TypeScript.

Back to Blog