UNPKG

528 BTypeScriptView Raw
1import type {IsUnknown} from './is-unknown';
2
3/**
4An if-else-like type that resolves depending on whether the given type is `unknown`.
5
6@see {@link IsUnknown}
7
8@example
9```
10import type {IfUnknown} from 'type-fest';
11
12type ShouldBeTrue = IfUnknown<unknown>;
13//=> true
14
15type ShouldBeBar = IfUnknown<'not unknown', 'foo', 'bar'>;
16//=> 'bar'
17```
18
19@category Type Guard
20@category Utilities
21*/
22export type IfUnknown<T, TypeIfUnknown = true, TypeIfNotUnknown = false> = (
23 IsUnknown<T> extends true ? TypeIfUnknown : TypeIfNotUnknown
24);