👋 Let's Connect! Follow me on GitHub for new projects.

Introduction

Node.js 23 brings an exciting experimental feature: the ability to execute TypeScript files directly without prior transpilation. This feature simplifies the development process, allowing developers to run TypeScript scripts just like JavaScript files.

In this article, we’ll explore how this experimental feature works, what types look like in Node.js 23, and how it affects type safety in your projects.

Experimental TypeScript Execution in Node.js 23

Node.js 23 introduces an experimental flag, --experimental-strip-types, that allows running TypeScript files by automatically stripping type annotations at runtime. This means you can write TypeScript and execute it without needing an explicit compilation step with tsc or Babel.

Enabling TypeScript Execution

To use this feature, you need:

  • Node.js 23 or later installed.
  • A TypeScript file (.ts) with type annotations.
  • The --experimental-strip-types flag when running the script.

How TypeScript Types Work in Node.js 23

While this feature enables execution, it does not perform type checking at runtime. Instead, it simply removes type annotations before execution. This makes it easier to work with TypeScript files but doesn’t replace static type checking.

Example 1: Running a Simple TypeScript Function

Let's create a simple TypeScript function and execute it in Node.js 23.

Step 1: Create a TypeScript file (example.ts)

function addNumbers(a: number, b: number): number {
    return a + b;
}

console.log(addNumbers(5, 10)); 

Step 2: Execute the TypeScript file directly

node --experimental-strip-types example.ts

Expected Output

15

In this example, Node.js removes the type annotations (: number) and executes the JavaScript equivalent of the function.

Example 2: Type Safety Considerations

Since Node.js 23 doesn’t perform static type checking, it’s possible to pass incorrect types without errors.

Type Mismatch Example

function greet(name: string) {
    return `Hello, ${name}!`;
}

// Node.js allows this, even though it's incorrect in TypeScript
console.log(greet(42)); 

Output

Hello, 42!

Normally, TypeScript would throw an error (Argument of type 'number' is not assignable to parameter of type 'string'), but Node.js 23 strips the types and executes the script without complaints.

Solution: Use tsc for Type Checking

To enforce type safety, run:

tsc example.ts

This will check for type errors before running the script.

Key Takeaways

✔ Node.js 23 allows direct execution of TypeScript files without pre-compilation.

✔ It removes type annotations at runtime but does not perform type checking.

✔ Use tsc in development to catch type errors before execution.

✔ This feature is experimental and may change in future Node.js versions.

Conclusion

The experimental TypeScript execution feature in Node.js 23 is a step toward tighter integration between Node.js and TypeScript. While it simplifies running TypeScript files, developers should still rely on static analysis tools to ensure type safety.

Want to try it out? Upgrade to Node.js 23 and test it in your next project! What do you think of this feature? Let us know in the comments.

Meta Description
Node.js 23 introduces experimental TypeScript execution with --experimental-strip-types. Learn how it works, its limitations, and best practices for type safety.

TLDR – Highlights for Skimmers

  • Node.js 23 allows running TypeScript files without prior transpilation.
  • The --experimental-strip-types flag removes type annotations at runtime.
  • No type checking is performed—use tsc for safety.
  • Great for rapid prototyping but not a replacement for TypeScript tooling.
  • Still experimental — future changes expected.

Have you tried this experimental feature in Node? Let me know what you think in the comments below!

Author Of article : Austin Read full article