type-fest/source/if-empty-object.d.ts
2025-05-13 01:05:53 +07:00

29 lines
666 B
TypeScript

import type {IsEmptyObject} from './empty-object.d.ts';
/**
An if-else-like type that resolves depending on whether the given type is `{}`.
@deprecated This type will be removed in the next major version. Use the {@link If} type instead.
@see {@link IsEmptyObject}
@example
```
import type {IfEmptyObject} from 'type-fest';
type ShouldBeTrue = IfEmptyObject<{}>;
//=> true
type ShouldBeBar = IfEmptyObject<{key: any}, 'foo', 'bar'>;
//=> 'bar'
```
@category Type Guard
@category Utilities
*/
export type IfEmptyObject<
T,
TypeIfEmptyObject = true,
TypeIfNotEmptyObject = false,
> = IsEmptyObject<T> extends true ? TypeIfEmptyObject : TypeIfNotEmptyObject;