type safety

Having a type checker such as TypeScript confirm that values have the expected shape before the code runs.

In more detail

A type-safe program is checked so that values are only used in ways their types allow, for example a number is never treated as an object. Type checkers catch these mistakes while you write code rather than when users hit them.

Example

Typing a CustomEvent's detail, as in CustomEvent<CartItem>, means a listener cannot misread the payload without the compiler complaining.

Related terms

Taught in

References