Value that can be undefined.
undefined
Union type useful for cases where a value might be undefined, and provides a simple way to express this in TypeScript. For example, the return type of a function that returns a string or undefined could be typed as Maybe<string>.
string
Maybe<string>
type MaybeNumber = Maybe<number>;const maybeNumber: MaybeNumber = 1;const notNumber: MaybeNumber = undefined; Copy
type MaybeNumber = Maybe<number>;const maybeNumber: MaybeNumber = 1;const notNumber: MaybeNumber = undefined;
The type of the value to make optional.
Value that can be
undefined
.Remarks
Union type useful for cases where a value might be
undefined
, and provides a simple way to express this in TypeScript. For example, the return type of a function that returns astring
orundefined
could be typed asMaybe<string>
.Example