CodePark/ questions / TypeScript on the server
START PRACTICINGPRACTICE
Backend question · TypeScript › TypeScript on the server

You run node src/server.ts on a Node version where type stripping is enabled by default (22.18+ or 23.6+), with no extra flags. Which line makes it fail?

enum Role { Admin, User }

The enum Role { Admin, User } line fails. Node only strips erasable syntax: type syntax it can remove without generating any code. An enum needs generated JavaScript, so it fails unless you add --experimental-transform-types.

The other three lines are pure type syntax, so Node just removes them:

•
interface User { id: string }
• the
: string annotations in function greet(name: string): string
•
import type { User } from "./types.ts";

TypeScript 5.8's
erasableSyntaxOnly option reports such constructs at compile time.