TSTypeScript

TypeScript glossary – key terms explained

any / unknown

any turns off type checking; unknown is the safe counterpart and requires a check before use.

Compiler (tsc)

The program that checks TypeScript for type errors and translates it into JavaScript.

Conditional type

A type with a condition T extends U ? X : Y; with infer you can pull out partial types.

Declaration file (.d.ts)

A file that describes only types, e.g. for JavaScript libraries. You can find many as @types/... packages (DefinitelyTyped).

Discriminated union

A union of object types with a common literal field by which the variant is determined unambiguously.

Generics

Type parameters such as <T> that make functions, classes and types reusable for many types.

Interface

Describes the shape of an object (fields and methods); interfaces with the same name are merged.

Intersection type

Combines several types into one that has all properties: A & B.

Literal type

A type that allows exactly one value, e.g. "up" or 42; together with unions a replacement for enums.

Mapped type

A type that iterates over the keys of another type: { [K in keyof T]: ... }.

Narrowing

Narrowing a type through checks such as typeof, instanceof or in, so that the compiler knows the more precise type.

never

The type for values that never occur – e.g. the return of a function that always throws, or a fully handled remainder of a union.

Structural typing

Types are compatible if their shape fits – regardless of names or declaration (as opposed to nominal typing).

tsconfig.json

The compiler's configuration file: target version, module system, strictness (strict) and which files are included.

Type alias

A name for an arbitrary type, given with type Name = ... – also for unions, tuples and function types.

Type erasure

During compilation all type information is removed; at runtime only JavaScript exists.

Type guard

A check or function (x is Type) that helps the compiler narrow a type.

Type inference

The compiler derives types automatically from values and context, so many annotations become unnecessary.

Union type

A type that can be one of several types: string | number.

Utility type

A built-in generic type such as Partial, Pick, Omit or Record that derives new types from existing ones.