Knowledge Maxxing
← Back to topic library
Dev MaxxingBeginnerTypeScript60 sec

TypeScript type

A TypeScript type describes the shape of a value, such as which properties an object has or what kind of data a variable can hold, checked before the code ever runs.

Prerequisite: JavaScript variable

What matters

Because types are checked ahead of time, many mistakes, like passing the wrong kind of value to a function, are caught while writing code instead of discovered later at runtime.

Example

Declaring a function parameter as 'name: string' lets TypeScript flag an error immediately if the function is called with a number instead.

Common misconception

TypeScript types do not exist at runtime in the final JavaScript; they are checked only while writing and compiling the code, then stripped out entirely.

Recall question

When are TypeScript's type checks actually performed, relative to when the code runs?

Keywords and related concepts

TypeScripttype checkingstatic typingtype inference

Related topics

Type inference
Dev MaxxingBeginner
JavaScript variable
Dev MaxxingBeginner