mirror of
https://github.com/sindresorhus/type-fest.git
synced 2026-01-18 14:53:13 +00:00
52 lines
1.1 KiB
TypeScript
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>;
|