Node.js รัน TypeScript โดยตรง v23.6+: node app.ts ไม่ต้อง tsc/esbuild
Back to articles

Node.js รัน TypeScript โดยตรง v23.6+: node app.ts ไม่ต้อง tsc/esbuild

Node.js 23.6+ รัน .ts/.mts/.cts native type stripping ESM/CommonJS production setup VS Code config migration guide performance vs tsx ts-node

Software Updated: January 9, 2026

Node.js รัน TypeScript โดยตรงตั้งแต่ v23.6.0 - node app.ts ไม่ต้องคอมไพล์!

Node.js 23.6+ รองรับไฟล์ .ts/.mts/.cts แบบ native ด้วย type stripping ลบ type annotation รันทันที รองรับ ESM/CommonJS

Node.js TypeScript Support

ไฟล์รองรับหมายเหตุ
.tsStandard TypeScript
.mtsES Module TS
.ctsCommonJS TS
.tsxReact JSX

รัน TypeScript ทันที

# ง่ายสุด
node app.ts

# ESM project
node --loader tsx app.ts

# Experimental features
node --experimental-transform-types app.ts

ตัวอย่างใช้งานจริง

app.ts

// Type annotations ลบอัตโนมัติ
interface User {
id: number;
name: string;
}

async function getUser(id: number): Promise<User> {
return { id, name: `User ${id}` };
}

// รันได้เลย node app.ts
const user = await getUser(1);
console.log(user);

package.json

{
"type": "module",
"scripts": {
"dev": "node --watch app.ts",
"start": "node app.ts"
}
}

ESM Import ต้องระบุ .ts

// ✅ ถูกต้อง
import { handler } from './routes.ts';
import express from 'express';

// ❌ Error - ไม่รู้ extension
import { handler } from './routes';

ข้อจำกัดสำคัญ

❌ ไม่มี type checking (ต้อง tsc --noEmit)
❌ tsconfig.json ถูก ignore
❌ Decorators/JSX ต้อง flag
❌ ไม่แปลง const enum/private fields
✅ Syntax TS 99% รองรับ

Production Setup แนะนำ

// tsconfig.json (type check เท่านั้น)
{
"tsBuildInfoFile": ".cache/tsbuildinfo",
"noEmit": true,
"strict": true
}
// package.json
{
"scripts": {
"typecheck": "tsc --noEmit",
"dev": "tsx watch src/index.ts",
"start": "node dist/index.js",
"build": "tsc"
}
}

Performance Comparison

MethodCold StartMemoryBuild Step
node app.ts25ms80MB❌ None
tsc → node35ms75MB✅ Type check
tsx45ms120MB⚠️ Runtime

VS Code Config

// settings.json
{
"typescript.preferences.includePackageJsonAutoImports": "on",
"typescript.suggest.autoImports": true,
"node.experimentalTypeAcquisition": true
}

Migration Guide

1. Node.js >= 23.6.0 ✅
2. package.json "type": "module"
3. ระบุ .ts extension ทุก import
4. tsc --noEmit (type check)
5. node app.ts 🚀
D

DRITESTUDIO

DRITESTUDIO COMPANY LIMITED - Cloud, VPS, Hosting and Colocation provider in Thailand

Manage your cookie settings

We use different types of cookies to optimize your experience on our website. Click on the categories below to learn more and customize your preferences. Note that blocking some types of cookies may impact your experience.

Necessary Cookies

These cookies are essential for the website to function properly. They enable basic functions like page navigation and access to secure areas.

View cookies used
  • Session cookies (session management)
  • Security cookies (CSRF protection)
Always On

Functional Cookies

These cookies enable personalized features like language preferences and theme settings. Without these, some features may not work properly.

View cookies used
  • lang (language preference)
  • theme (dark/light mode)

Analytics Cookies

These cookies help us understand how visitors interact with our website by collecting and reporting information anonymously.

View cookies used
  • _ga (Google Analytics)
  • _gid (Google Analytics)

Marketing Cookies

These cookies are used to track visitors across websites to display relevant advertisements based on your interests.

View cookies used
  • Advertising cookies
  • Remarketing pixels

Privacy Policy