v4.7 and above stopped supporting a type pattern that used to work in v4.6 (Key Remapping in Mapped Type)
See original GitHub issueBug Report
In version 4.7 and above a patter ([P in TName as P]:
) causes types to break. It’s really strange, since it does work if used in some ways, but if used to pass down to a method argument, it will result in type unknown
.
See playground links for examples.
🕗 Version & Regression Information
A friendly person in the comments of my original stackoverflow question comments narrowed it down to this: between 2022-03-15 and 2022-03-16
⏯ Playground Link
💻 Code
The issue was caused by the following types:
[P in TName as P]:
which does not work anymore in v4.7 and needs to be
[P in TName]:
(I had it like this, because I used to exclude a type like this: [P in TName as P extends UnacceptedPaths ? never : P]:
)
🙁 Actual behavior
One of the nested types receives type unknown
to it’s params, when it should be properly inferred from the code.
🙂 Expected behavior
Should work like in v4.6 - type should be inferred. If I remember correctly, I came up with the problematic type from this.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
@ahejlsberg here’s a simplified version that presents as an implicit
any
regression:Can we tweak back the originating PR to still allow inferences from mapped types where the
as
clause is of the form[K in T as expr ? K : never]
/[K in T as expr ? never : K]
?Clarification, because I got confused: The issue only appears when you remove this line from the 4.7 playground: