type-fest/source/simplify-deep.d.ts
Haozheng Li 3a04fcf2ad
Add SimplifyDeep type (#882)
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
2024-06-04 12:31:55 +02:00

52 lines
1.1 KiB
TypeScript

import type {ConditionalSimplifyDeep} from './conditional-simplify';
/**
Deeply simplifies an object type.
Useful to flatten the type output to improve type hints shown in editors.
@example
```
import type {SimplifyDeep} from 'type-fest';
type Properties1 = {
height: number;
position: {
top: number;
bottom: number;
};
};
type Properties2 = {
width: number;
position: {
left: number;
right: number;
};
};
type Properties = Properties1 & Properties2;
// In your editor, hovering over `Props` will show the following:
//
// type Properties = Properties1 & Properties2;
type SimplifyDeepProperties = SimplifyDeep<Properties1 & Properties2>;
// But if wrapped in SimplifyDeep, hovering over `Props` will show a flattened object with all the properties:
//
// SimplifyDeepProperties = {
// height: number;
// width: number;
// position: {
// top: number;
// bottom: number;
// left: number;
// right: number;
// };
// };
```
@see Simplify
@category Object
*/
export type SimplifyDeep<Type> = ConditionalSimplifyDeep<Type, Function | Iterable<unknown>, object>;