-
-
Notifications
You must be signed in to change notification settings - Fork 502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
idea: Omit/PickDeep type #343
Labels
Comments
👍 |
Would love to see this type. |
Looks like it's implemented decently soundly here (appears to still function in TS 4.8): Link to SO answer featuring this: Copypasta of code, for completeness: /** Union of primitives to skip with deep omit utilities. */
type Primitive = string | Function | number | boolean | Symbol | undefined | null
/** Deeply omit members of an array of interface or array of type. */
export type DeepOmitArray<T extends any[], K> = {
[P in keyof T]: DeepOmit<T[P], K>
}
/** Deeply omit members of an interface or type. */
export type DeepOmit<T, K> = T extends Primitive ? T : {
[P in Exclude<keyof T, K>]: //extra level of indirection needed to trigger homomorhic behavior
T[P] extends infer TP ? // distribute over unions
TP extends Primitive ? TP : // leave primitives and functions alone
TP extends any[] ? DeepOmitArray<TP, K> : // Array special handling
DeepOmit<TP, K>
: never
}
/** Deeply omit members of an array of interface or array of type, making all members optional. */
export type PartialDeepOmitArray<T extends any[], K> = Partial<{
[P in Partial<keyof T>]: Partial<PartialDeepOmit<T[P], K>>
}>
/** Deeply omit members of an interface or type, making all members optional. */
export type PartialDeepOmit<T, K> = T extends Primitive ? T : Partial<{
[P in Exclude<keyof T, K>]: //extra level of indirection needed to trigger homomorhic behavior
T[P] extends infer TP ? // distribute over unions
TP extends Primitive ? TP : // leave primitives and functions alone
TP extends any[] ? PartialDeepOmitArray<TP, K> : // Array special handling
Partial<PartialDeepOmit<TP, K>>
: never
}> |
Closed
Thank you @Emiyaaaaa for contributing to close this issue! ⭐ The rewards from this issue, totalling $130, has been shared with you. What now?
If you already have a Polar account setup, you don't need to do anything. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In my codebase we ended up with a type like this:
The idea is to omit from
FilterableSelectProps<{value: string, text: string}>
the value atuseComboboxProps.itemToString
but expressing that ends up with a pretty hard to read type. Would be nice to have deep versions ofOmit
andPick
.Upvote & Fund
The text was updated successfully, but these errors were encountered: