Skip to content

Instantly share code, notes, and snippets.

@andrezsanchez
Created December 5, 2022 00:19
Show Gist options
  • Save andrezsanchez/4c7cc1c245487955e184d3d25ce0e2a0 to your computer and use it in GitHub Desktop.
Save andrezsanchez/4c7cc1c245487955e184d3d25ce0e2a0 to your computer and use it in GitHub Desktop.
TypeScript distribute intersection
type X = { a: number; z: string };
type Y = { a: 6; b: number };
// TS shows:
// X & Y
type XY1 = X & Y;
type DistributeIntersection<A, B> = Pick<A & B, keyof A | keyof B>;
// TS shows:
// { a: 6; b: number; z: string }
type XY2 = DistributeIntersection<X, Y>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment