Menu

What your TypeScript becomes when it runs
πŸ“°

What your TypeScript becomes when it runs

DEV Community: typescriptΒ·JSLabΒ·26 days ago
#UfHeMQTI
#devtotypescript#devto#dev#level#enter
Long article (640 words) β€” no AI summary yet.
Reading 0:00
15s threshold

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.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.