-
-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Sindre Sorhus <[email protected]>
- Loading branch information
1 parent
5ad462a
commit 3a04fcf
Showing
7 changed files
with
87 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {expectType} from 'tsd'; | ||
import type {SimplifyDeep} from '../index'; | ||
|
||
type Properties1 = { | ||
height: number; | ||
position: { | ||
top: number; | ||
bottom: number; | ||
}; | ||
}; | ||
|
||
type Properties2 = { | ||
width: number; | ||
position: { | ||
left: number; | ||
right: number; | ||
}; | ||
}; | ||
|
||
// Flatten the type output to improve type hints shown in editors. | ||
declare const flattenProperties: { | ||
height: number; | ||
width: number; | ||
position: { | ||
top: number; | ||
bottom: number; | ||
left: number; | ||
right: number; | ||
}; | ||
}; | ||
expectType<SimplifyDeep<Properties1 & Properties2>>(flattenProperties); |