TypeScript · Types and shapes

null and undefined

With strictNullChecks, null and undefined are separate types and must be handled explicitly.

Syntax
string | null

Example

Example
type Maybe = string | null;
function len(value: Maybe) {
  return value ? value.length : 0;
}

More in this group

any Array types enums Function type Interface Literal type never Optional property

Learn this in the course

Reference pages are the quick answer. The course explains the why, shows the full example and ends with a challenge.

Open the course