Created
December 5, 2022 00:19
-
-
Save andrezsanchez/4c7cc1c245487955e184d3d25ce0e2a0 to your computer and use it in GitHub Desktop.
TypeScript distribute intersection
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
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