type-fest/source/if-null.d.ts
2024-04-24 14:06:40 +07:00

25 lines
483 B
TypeScript

import type {IsNull} from './is-null';
/**
An if-else-like type that resolves depending on whether the given type is `null`.
@see {@link IsNull}
@example
```
import type {IfNull} from 'type-fest';
type ShouldBeTrue = IfNull<null>;
//=> true
type ShouldBeBar = IfNull<'not null', 'foo', 'bar'>;
//=> 'bar'
```
@category Type Guard
@category Utilities
*/
export type IfNull<T, TypeIfNull = true, TypeIfNotNull = false> = (
IsNull<T> extends true ? TypeIfNull : TypeIfNotNull
);