UNPKG

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