Node.js Native TypeScript
TypeScript types can document a contract, but removing type syntax does not prove that the program satisfies that contract. Keep execution and static checking separate.
How it works
The native type-stripping capability differs between the reviewed Node versions. Node 22.15.1 uses the explicit experimental-strip-types flag for this small erasable-syntax fixture; Node 24.22.1 runs it directly. Neither route replaces a TypeScript checker, transforms every TypeScript feature or reads a complete bundler configuration. The source writes one owned .ts file and executes it with the same Node interpreter that launched the lesson.
Run the code
Run this example locally with Node.js. The exact sources are reviewed on Node 22.15.1 and Node 24.22.1 unless a specialised lab states otherwise. Save the complete source as typescript-native.mjs in a separate empty exercises folder and run node typescript-native.mjs. There is no Node.js browser runner on Bhylu; the plain JavaScript playground does not provide these filesystem, server or process APIs.
Download the complete source. Ordinary Node scripts need no Apache, PHP or MySQL service. File examples own their temporary folders; network fixtures use loopback and available temporary ports.
Example
import { mkdtemp, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
const folder = await mkdtemp(join(tmpdir(), 'bhylu-node-'));
import { writeFile } from 'node:fs/promises';
import { spawnSync } from 'node:child_process';
try {
const file = join(folder, 'quantity.ts');
await writeFile(file, 'const quantity: number = 3; console.log(quantity * 2);\n', {
flag: 'wx',
});
const flags =
Number(process.versions.node.split('.')[0]) < 24
? ['--experimental-strip-types']
: [];
const result = spawnSync(process.execPath, [...flags, file], {
encoding: 'utf8',
timeout: 5000,
windowsHide: true,
});
if (result.status !== 0) throw new Error(result.stderr);
console.log(result.stdout.trim());
} finally {
await rm(folder, { recursive: true, force: true });
}
Expected result
6
The child executes a typed declaration after erasing its type annotation. Node 22 can emit an experimental warning on that child’s stderr. The next lesson runs the actual TypeScript checker and deliberately supplies a rejected assignment.
Use the Node.js API reference for the precise version contract.