Last active
April 1, 2025 04:25
-
-
Save desnor/cbb0ac9dbf6e5120db330d5d4de50b7b to your computer and use it in GitHub Desktop.
Helper to perform an intersection removal for an object type - removing any values from first input's properties that match the properties of the second input
This file contains hidden or 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
type RemoveIntersection< | |
T extends Record<PropertyKey, any>, | |
TRemove extends Record<PropertyKey, any> | |
> = { [K in keyof T]: K extends keyof TRemove ? Exclude<T[K], TRemove[K]> : T[K] }; | |
/** | |
* example | |
* type V = RemoveIntersection<{ a: string | null; b: number | undefined }, { a: null; b: undefined }>; | |
* => type V is {a: string; b: number } | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment