LogicLoop Logo
LogicLoop
LogicLoop / devops-practices / Node.js 22.6+ Now Runs TypeScript Natively: No Compiler Needed
devops-practices June 4, 2025 4 min read

How to Use Node.js Native TypeScript Support: Run TS Code Without Compilation

Jamal Washington

Jamal Washington

Infrastructure Lead

Node.js 22.6+ Now Runs TypeScript Natively: No Compiler Needed

Since version 22.6, Node.js has included native TypeScript support, allowing developers to run TypeScript code directly without a compilation step. This groundbreaking feature eliminates the need for tools like ts-node or alternative runtimes like Bun or Deno when you simply want to execute TypeScript in a Node.js environment. With TypeScript 5.8's release, this integration has become even more powerful.

How Node.js Native TypeScript Support Works

Node.js uses a "strip-only" approach by default when running TypeScript code. Instead of compiling your TypeScript to JavaScript behind the scenes (which would be slower), it simply ignores the TypeScript-specific parts of your code. This makes execution faster but comes with some limitations you need to understand.

For example, when Node.js encounters type annotations on function parameters, it simply strips them away since they don't affect runtime behavior. However, features like enums that generate actual JavaScript code can't be handled through simple stripping.

Setting Up Your Project for Node.js Native TypeScript

To use Node.js native TypeScript support effectively, you'll need to make three important adjustments to your codebase:

  1. Add the 'type' keyword to type-only imports (interfaces, types, etc.)
  2. Import from .ts files directly instead of .js files
  3. Avoid TypeScript features that can't be stripped (like enums and namespaces)

1. Annotate Type-Only Imports

When importing TypeScript-specific constructs like interfaces or types, you need to add the 'type' keyword to your import statements. This tells Node.js that these imports don't exist at runtime and should be ignored.

TYPESCRIPT
// Before
import { UserInterface } from './types';

// After - with type annotation
import type { UserInterface } from './types';
1
2
3
4
5
Adding the 'type' keyword to imports prevents errors when running TypeScript with Node.js native support
Adding the 'type' keyword to imports prevents errors when running TypeScript with Node.js native support

2. Import from TypeScript Files

When using Node.js native TypeScript support, you should import directly from .ts files rather than .js files. This is different from the approach you'd take when compiling TypeScript to JavaScript first.

TYPESCRIPT
// Before (when compiling to JS first)
import { router } from './routes.js';

// After (for native TS support)
import { router } from './routes.ts';
1
2
3
4
5

3. Configure Your tsconfig.json

You'll need to update your tsconfig.json file with several important settings to make everything work smoothly:

JSON
{
  "compilerOptions": {
    "allowImportingTsExtensions": true,
    "noEmit": true,
    "verbatimModuleSyntax": true
  }
}
1
2
3
4
5
6
7
  • allowImportingTsExtensions: Enables importing .ts files directly
  • noEmit: Prevents TypeScript from generating output files (since Node.js will handle the code directly)
  • verbatimModuleSyntax: Forces you to use the 'type' keyword for type-only imports

TypeScript 5.8's New Feature: erasableSyntaxOnly

TypeScript 5.8 introduces a valuable new option called "erasableSyntaxOnly" that enhances the Node.js native TypeScript experience. When set to true in your tsconfig.json, this option warns you if you're using TypeScript features that can't be erased by simple stripping.

JSON
{
  "compilerOptions": {
    "allowImportingTsExtensions": true,
    "noEmit": true,
    "verbatimModuleSyntax": true,
    "erasableSyntaxOnly": true
  }
}
1
2
3
4
5
6
7
8

With this setting enabled, your IDE will show warnings or errors when you use features like enums that won't work with Node.js's default strip-only mode. This helps you catch potential runtime issues during development.

Features that can't be stripped away may cause runtime errors with Node.js native TypeScript support
Features that can't be stripped away may cause runtime errors with Node.js native TypeScript support

Dealing with Non-Strippable Features

When using Node.js native TypeScript support, you'll need to replace certain TypeScript features with alternatives that can be stripped away:

  • Instead of enums, use string literal union types
  • Avoid namespace syntax in favor of ES modules
  • Use type assertions carefully
TYPESCRIPT
// Instead of this enum (won't work with strip-only mode)
enum TodoStatus {
  ACTIVE = 'active',
  COMPLETED = 'completed'
}

// Use this string literal union type instead
type TodoStatus = 'active' | 'completed';
1
2
3
4
5
6
7
8

Using Transform Mode for Full TypeScript Support

If you absolutely need to use TypeScript features that can't be stripped away, Node.js does offer a transformation mode as an alternative to the default strip-only approach. This mode fully compiles your TypeScript code to JavaScript before execution.

Node.js offers both strip mode and transformation mode for TypeScript support
Node.js offers both strip mode and transformation mode for TypeScript support

To use transformation mode, add the --experimental-wasm-modules flag when running your Node.js application:

BASH
node --experimental-transform-types app.ts
1

While this enables all TypeScript features, it comes with a performance cost since your code must be compiled at runtime. For optimal performance, the strip-only mode is preferred when possible.

Benefits of Node.js Native TypeScript Support

  • Simplified development workflow without separate compilation steps
  • No need for additional tools like ts-node
  • Faster execution compared to traditional TypeScript compilation
  • Seamless integration with the Node.js ecosystem
  • Improved developer experience with direct execution of TypeScript files

Conclusion

Node.js native TypeScript support represents a significant step forward for TypeScript developers. With TypeScript 5.8's new erasableSyntaxOnly option, it's now easier than ever to write TypeScript code that runs directly in Node.js without compilation. By understanding the limitations of the strip-only approach and making the necessary adjustments to your codebase, you can enjoy a streamlined development experience while maintaining the benefits of TypeScript's type safety.

Whether you're building a new Node.js application or maintaining an existing one, consider leveraging this native TypeScript support to simplify your workflow and improve your development experience.

Let's Watch!

Node.js 22.6+ Now Runs TypeScript Natively: No Compiler Needed

Ready to enhance your neural network?

Access our quantum knowledge cores and upgrade your programming abilities.

Initialize Training Sequence
L
LogicLoop

High-quality programming content and resources for developers of all skill levels. Our platform offers comprehensive tutorials, practical code examples, and interactive learning paths designed to help you master modern development concepts.

© 2025 LogicLoop. All rights reserved.