Skip to content

Optional Property

In one line

An optional property (prop?: Type) is a property that can be absent or undefined. The question mark before the colon marks it as optional.

In simple words

An optional property is one that an object may or may not have. You declare it with a question mark: email?: string. TypeScript treats it as string | undefined — the property is either a string or not present.

Optional properties are useful for partial data, API responses with optional fields, and configuration objects where not all settings are required. They work with optional chaining (?.) for safe access.

The Partial<T> utility type makes all properties optional. The Required<T> utility type makes all properties required (removes the ?).

Example

typescript
interface User {
  name: string;
  email?: string; // optional
}

const u1: User = { name: "Alice" };           // OK, email omitted
const u2: User = { name: "Bob", email: "b@x" }; // OK, email provided
console.log(u1.email?.toUpperCase()); // undefined (optional chaining)

Optional properties can be omitted. Optional chaining safely accesses them.

Related terms

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary