TypeScript Types

null — explicit absent value

With strictNullChecks enabled, null is its own type and cannot be assigned to an ordinary string or number. Use a union such as string | null to represent a value that may be deliberately absent. A runtime equality guard can establish that the non-null branch contains a string. With strictNullChecks disabled, assignability is looser. Example output: "unavailable". The example was designed for strict checking with an ES2022 target; type annotations do not add runtime validation.

Formal Syntax & Structure

typescript syntaxtypescript
let value: null;

Working Example

Example Snippettypescript
function label(value: string | null): string {  return value === null ? "unavailable" : value;}console.log(label(null));
TypeScript Reference