You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This changed between versions 3.3.3333 (where it worked) and 3.5.1 (where I see the same errors as on the most recent TS version) based on the playground
All return statements in the parseValue function result in an error that looks something like:
Type 'number' is not assignable to type 'TypeToValueMap[T]'.
Type 'number' is not assignable to type 'never'.(2322)
This is incorrect because there is no value of T (which must be a member of SomeTypes) that has no mapping into TypeToValueMap, which means that there is no case where narrowing the type should result in never in TypeToValueMap[T].
🙂 Expected behavior
The code as written should have no errors because I am narrowing type to a specific value in SomeTypes, which should provide the TS compiler enough info to map into TypeToValueMap[T].
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
Ah, looks like it is, thanks. Followed that to the original issue: #33014 . Looks like it is potentially desired but not currently planned, and that thread has some workarounds.
🔎 Search Terms
mapped type, map narrowing, generic mapped type, generic narrowing, generic return
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.6.2#code/KYOwrgtgBAyg9hYAVAngB2AZygbwFBSFQCGANAUQEblFQDGeAvnngC7rBSoZJwBqxADZhgAWWJooAXlwVCAbXiJuWAHTEAugC4o4CJWAAnGkUUJkHTKsraolOHEHBiIEwqUWMVurcytDAJYgAOZMLHRwIH5QaMSGmMACwpwyADxIUMAAHqygACbYHiqYAHwAFABuQiI6foEhpFDsGDpIAJStHLxJIuJo8kga0iWytAEAZlBlzSlSMkWW6m2jtESGwKxghiBQAHKQBoaV1cBtANxyUMyXE1Mz0nOw5sXWy-iraxtbOwBCDk4uY7Jc6Xa5jSbTDgPebPRZ0N6XWjrTbbKBVZIXWhgoisAAWhjgAHddMBiQBRQwEo4AcgAkiB0QE8k0ONSQdcIlFHMBVII4MEyhRYvFEicytSAIzUxoLLxLEzChI9YDiqUy2FyyhtBVxJViyXSp7KOFtPBtIA
💻 Code
🙁 Actual behavior
All return statements in the
parseValue
function result in an error that looks something like:This is incorrect because there is no value of T (which must be a member of SomeTypes) that has no mapping into TypeToValueMap, which means that there is no case where narrowing the type should result in
never
in TypeToValueMap[T].🙂 Expected behavior
The code as written should have no errors because I am narrowing
type
to a specific value inSomeTypes
, which should provide the TS compiler enough info to map intoTypeToValueMap[T]
.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: