Incomplete typecheck when assigning to a mapped object type with remapped keys #60070
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
🔎 Search Terms
typechecker, mapped object type, remapped keys, ts2322
🕗 Version & Regression Information
nightly
and every version down to 4.1.5 (first version supporting remapped keys)⏯ Playground Link
https://www.typescriptlang.org/play/?#code/C4TwDgpgBAygFgQ0lAvFA3lAZgexwLigGdgAnASwDsBzAbigCMFTDKBXAWwYlPoF9aAKFDJ4SCAFkkqDNjyEA5LhwAmBfSYsoCzWv5CR0KWEgATMcjSYA2gGkoVKAGsIIHFliJkCIp-HG7AF1AwgsIIKgBQUEsNkoAY2ByHEooDiQANQQAGzYIAB57CAAPYAhKU18XNw8wgD4ACkEoFudXQlsAGmbWoi8IUP7u1rSkM0JjMzDh1vSwQf8kboBKDB6W+JSSUZMIU1tXGTnrasChEc3KbYA3HLyZPvET1zP1nbNrObMDkECZW9yECEfCAA
💻 Code
🙁 Actual behavior
The error says
The second line is correct,
Shape
is different fromMappedShape
since they don't have any property names in common (which is the idea 🙂). That incompatibility is not relevant when it's the value inShape[K]
that should be assignable toMappedShape[ShapeMap[K]]
.To an uninitiated eye it looks like the typechecking either ends too early or too late since it compares the wrong types when trying to do the assignment. That's just a guess that might be incorrect so take that with all the salt you want 👍
🙂 Expected behavior
Assigning
Shape[K]
toMappedShape[ShapeMap[K]]
should be allowed since they are the same types when resolved.Additional information about the issue
If changing the code to always take
foo
as the key (Playground) it works correctly:The text was updated successfully, but these errors were encountered: