TypeScript has a simple story: types are checked, then erased, and what runs is JavaScript. That's true for almost every line you write. The exceptions are worth knowing, because they're the lines that behave differently from how they look.
The part that disappears
interface User { name : string ; age : number ; }
import type { Config } from "./config" ;
const users : User [ ] = JSON . parse ( raw ) as User [ ] ; const theme = { dark : true } satisfies Record < string , boolean > ; function greet ( u : User ) : string { return `Hi ${u.name}` ; }
Enter fullscreen mode
Exit fullscreen mode
Run it through any TypeScript compiler and you get, give or take whitespace:
const users = JSON . parse ( raw ) ; const theme = { dark : true } ; function greet ( u ) { return `Hi ${u.name}` ; }
Enter fullscreen mode
Exit fullscreen mode
The interface, the import type , the annotations, as and satisfies : all gone.β¦