mirror of
https://github.com/sindresorhus/type-fest.git
synced 2025-12-08 19:25:05 +00:00
25 lines
483 B
TypeScript
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
|
|
);
|