literal type

A type that allows exactly one value, such as the string "GET", the number 404 or true.

In more detail

On their own they are rarely useful, but a union of literals such as "GET" | "POST" lists every valid value and rejects typos at compile time. const variables get literal types automatically; object properties need as const or a const type parameter to keep them.

Example

type HttpMethod = "GET" | "POST" | "PUT" | "DELETE";

Related terms

Taught in

References