mirror of
https://github.com/sindresorhus/type-fest.git
synced 2025-12-08 19:25:05 +00:00
31 lines
647 B
TypeScript
31 lines
647 B
TypeScript
import type {IsAny} from './is-any.d.ts';
|
|
|
|
/**
|
|
Returns a boolean for whether the given type includes `null`.
|
|
|
|
Note: The built-in `NonNullable` type removes both `null` and `undefined`, which is not accurate for the name.
|
|
|
|
@example
|
|
```ts
|
|
import type {IsNullable} from 'type-fest';
|
|
|
|
type A = IsNullable<string>;
|
|
//=> false
|
|
|
|
type B = IsNullable<string | null>;
|
|
//=> true
|
|
|
|
type C = IsNullable<string | undefined>;
|
|
//=> false
|
|
|
|
type D = IsNullable<string | null | undefined>;
|
|
//=> true
|
|
```
|
|
|
|
@category Type Guard
|
|
@category Utilities
|
|
*/
|
|
export type IsNullable<T> = IsAny<T> extends true ? true : Extract<T, null> extends never ? false : true;
|
|
|
|
export {};
|