UNPKG

562 BTypeScriptView Raw
1import type {IsEmptyObject} from './empty-object';
2
3/**
4An if-else-like type that resolves depending on whether the given type is `{}`.
5
6@see {@link IsEmptyObject}
7
8@example
9```
10import type {IfEmptyObject} from 'type-fest';
11
12type ShouldBeTrue = IfEmptyObject<{}>;
13//=> true
14
15type ShouldBeBar = IfEmptyObject<{key: any}, 'foo', 'bar'>;
16//=> 'bar'
17```
18
19@category Type Guard
20@category Utilities
21*/
22export type IfEmptyObject<
23 T,
24 TypeIfEmptyObject = true,
25 TypeIfNotEmptyObject = false,
26> = IsEmptyObject<T> extends true ? TypeIfEmptyObject : TypeIfNotEmptyObject;