mirror of
https://github.com/sindresorhus/type-fest.git
synced 2025-12-08 19:25:05 +00:00
29 lines
545 B
TypeScript
29 lines
545 B
TypeScript
import type {IsAny} from './is-any.d.ts';
|
|
|
|
/**
|
|
Returns a boolean for whether the given type includes `undefined`.
|
|
|
|
@example
|
|
```ts
|
|
import type {IsOptional} from 'type-fest';
|
|
|
|
type A = IsOptional<string>;
|
|
//=> false
|
|
|
|
type B = IsOptional<string | undefined>;
|
|
//=> true
|
|
|
|
type C = IsOptional<string | null>;
|
|
//=> false
|
|
|
|
type D = IsOptional<string | null | undefined>;
|
|
//=> true
|
|
```
|
|
|
|
@category Type Guard
|
|
@category Utilities
|
|
*/
|
|
export type IsOptional<T> = IsAny<T> extends true ? true : Extract<T, undefined> extends never ? false : true;
|
|
|
|
export {};
|