Type inference not working as expected when using key remapping in mapped types #44115
Labels
Needs Investigation
This issue needs a team member to investigate its status.
Milestone
Bug Report
🔎 Search Terms
mapped types, key remapping using as, type inference
🕗 Version & Regression Information
I tested this with all versions available on typescriptlang.org/play including nightly. I was unable to test this on versions < 4.1 because key-remapping does not exist prior to version 4.1.
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
I might be misusing the key remapping feature, but while implementing the above mentioned
match
function, I ran into following behavior:match
above with explicit generic types works as expected (Example 1)any
(Example 2), even that intellisense initially proposes the correct type while typing (see [1])match
, the expected type of the argument isK
instead ofT
.🙂 Expected behavior
_case
to require an argument of typeV
as declared in the mapped type ((variant: V) => R
).MatchCases
, the argument of the Some-handler should be inferred to typeSome<number>
.[1]:
The text was updated successfully, but these errors were encountered: