forked from sindresorhus/type-fest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
is-if-unknown.d.ts
40 lines (31 loc) · 972 Bytes
/
is-if-unknown.d.ts
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
31
32
33
34
35
36
37
38
39
40
/** Returns a boolean for whether the given type is `null`. */
type IsNull<T> = [T] extends [null] ? true : false;
/**
Returns a boolean for whether the given type is `unknown`.
@link https://github.com/dsherret/conditional-type-checks/pull/16
@example
```
import type {IsUnknown} from 'type-fest';
```
@category Utilities
*/
export type IsUnknown<T> = (
unknown extends T // `T` can be `unknown` or `any`
? IsNull<T> extends false // `any` can be `null`, but `unknown` can't be
? true
: false
: false
);
/**
If the given type `T` is `unknown`, the returned type is `TypeIfUnknown`.
Otherwise, the return type is `TypeIfNotUnknown`. If only `T` is specified,
`TypeIfUnknown` will be `true` and `TypeIfNotUnknown` will be false.
@example
```
import type {IfUnknown} from 'type-fest';
```
@category Utilities
*/
export type IfUnknown<T, TypeIfUnknown = true, TypeIfNotUnknown = false> = (
IsUnknown<T> extends true ? TypeIfUnknown : TypeIfNotUnknown
);