TypeScript · Types and shapes

Optional property

The property may be missing or undefined. Do not use it for values that are always present but sometimes empty.

Syntax
name?: string

Example

Example
type Profile = { name: string; bio?: string };
const profile: Profile = { name: "Ada" };

More in this group

any Array types enums Function type Interface Literal type never null and undefined

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