mirror of
https://github.com/sindresorhus/type-fest.git
synced 2025-12-08 19:25:05 +00:00
27 lines
562 B
TypeScript
27 lines
562 B
TypeScript
import type {IsEmptyObject} from './empty-object';
|
|
|
|
/**
|
|
An if-else-like type that resolves depending on whether the given type is `{}`.
|
|
|
|
@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;
|