type annotation

A type written explicitly after a name with a colon, such as name: string, to tell the compiler what a value must be.

In more detail

Annotations are most useful on function parameters, exported functions and public interfaces, where they document the contract. Inside a function, local variables usually get their type by inference, so annotating them is redundant. Annotations are erased when the code is compiled.

Example

function sendWelcome(user: User): string

Related terms

Taught in

References