Optional properties

Add a ? after a property name to mark it as optional.

When a property is optional, it either has a value of undefined or is not present in an object's keys. Keep in mind that undefined is different from null, so you would need to specifically include null to include it in the type.

Loading TypeScript...

If a key is not marked as optional, it is required. An object that is missing a required key will generate a TypeScript error.

Was this page helpful?