type erasure

The removal of all TypeScript types when code is compiled, so none of them exist while the JavaScript runs.

In more detail

Because types are erased, they add zero bytes to the output and zero run time cost. It also means you cannot ask at run time whether a value is of an interface type; you must check its actual shape with JavaScript code. Data from outside the program, such as a network request, is never protected by types alone.

Example

let n: number = 1  compiles to  let n = 1

Related terms

Taught in

References