The results of the 'Mapped Types' distribution have changed.
See original GitHub issueBug Report
The conversion result of ‘Mapped Types’ has changed in 4.3.2 or later typescript.
💻 Code
type Base = { 100: { a: number }; 200: { b: string } }
type NewType<T = Base> = {
[P in keyof T ]: {
code: P
body: T[P]
}
} extends {
[P in any]: infer R
}
? R
: never
let test: NewType
🙁 Actual behavior
- 4.3.0-beta and earlier
let test: {
code: 100;
body: {
a: number;
};
} | {
code: 200;
body: {
b: string;
};
}
- 4.3.2
let test: {
code: keyof Base;
body: {
a: number;
} | {
b: string;
};
}
🙂 Expected behavior
Hoping to return to pre-4.3.0-beta behavior!
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Mapped Types should distribute over union types · Issue #28339
At least the title should be changed from "Mapped types" to "Mapped types that are a function of keys ". Otherwise it is...
Read more >Typescript: mapped types, strip field from a union
This means that the mapped type is applied independently to each member of the union and all results are unioned into the final...
Read more >KB5014754—Certificate-based authentication changes on ...
In general, mapping types are considered strong if they are based on identifiers that you cannot reuse. Therefore, all mapping types based on...
Read more >Exploring TypeScript Mapped Types Together | HackerNoon
What works for me when building complex mapped types is starting simple and then incrementally adding complexity.
Read more >3.2 Thematic Maps | GEOG 160: Mapping our Changing World
A wide array of map types has been developed over the years to represent ... The goal of choropleth maps is to depict...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Another workaround (tried on ts 4.4.0-dev.20210530):
I think our syntactic inference constraint rules are kiiiiiinda arbitrary to begin with (what type parameters we match up across what locations has kinda been chosen by request) - I “fixed” the issue by adding one because the change in behavior was technically a regression, and adding those syntactic constraints is sort-of free to do. The extra instantiation would probably be the best thing we could do to keep the old behavior going. We could back it out… But then we’d be reintroducing the old regression…