Search⌘ K
AI Features

Optionality

Explore how to define and check optional parameters and properties in TypeScript under strict null checking. Understand the difference between explicit undefined values and optional parameters, and use type guards to safely work with nullable types. This lesson helps you write clearer, more robust code that handles optionality effectively.

We'll cover the following...

Defining optionality

As you saw in the previous lesson, strict null checks force you to explicitly distinguish between values that can be null or undefined and those that cannot be. You already saw how to do this with a union type.

interface Person {
  name: string;
}

let nullableJohn: Person | null;
let maybeUndefinedBob: Person | undefined;
let ambiguoslyEmptyAlice: Person | null | undefined;

There is ...