Last active
April 18, 2022 18:45
-
-
Save jfet97/9a081c1356c694f2ef51925e2376e083 to your computer and use it in GitHub Desktop.
Mapped types distribute as well
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 Nodes = | |
| { | |
type: "a"; | |
age: number; | |
} | |
| { | |
type: "b"; | |
size: string; | |
}; | |
type Validation<T> = { | |
// T is naked | |
[P in keyof T]: boolean; | |
}; | |
type R = Validation<Nodes>; | |
// Validation<{ type: "a"; age: number; }> | Validation<{ type: "b"; size: string; }> | |
// | |
// Nodes is an union of types && mapped type is homomorphic | |
// => the mapped type distributes over the constituents of the union | |
// => the result is the union of the resulting mapped types |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment