optional property
An object property marked with a question mark, such as bio?: string, which may be left out.
In more detail
By default an optional property also accepts an explicit undefined value. exactOptionalPropertyTypes removes that, so the key must be either missing or a real value. Partial makes every property optional; Required removes the question marks.
Related terms
- exactOptionalPropertyTypes — The compiler option that forbids setting an optional property to undefined explicitly, so it must be omitted or given a real value.
- undefined — The JavaScript value meaning not set: a variable with no value yet, a missing property or a function that returned nothing.
- Partial<T> — The utility type that makes every property of T optional, used for update or patch payloads.
- Required<T> — The utility type that removes the question mark from every property of T, making all of them required.
Taught in
- void, undefined And null: Exact Optional Property Types — Production TypeScript
- Type Aliases Versus Interfaces: Declaration Merging — Production TypeScript
- Optional Properties, Readonly And Index Signatures — Production TypeScript
- Discriminated Unions: Tagged Variants And Pattern Matching — Production TypeScript
- Core Utilities: Partial, Required, Readonly, Pick And Omit — Production TypeScript