-
-
Notifications
You must be signed in to change notification settings - Fork 679
Expand file tree
/
Copy pathis-nullable.d.ts
More file actions
30 lines (21 loc) · 647 Bytes
/
is-nullable.d.ts
File metadata and controls
30 lines (21 loc) · 647 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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 {};