Skip to content

Instantly share code, notes, and snippets.

@desnor
Last active April 1, 2025 04:25
Show Gist options
  • Save desnor/cbb0ac9dbf6e5120db330d5d4de50b7b to your computer and use it in GitHub Desktop.
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
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