Skip to content

v4.7 and above stopped supporting a type pattern that used to work in v4.6 (Key Remapping in Mapped Type) #51141

@josias-r

Description

@josias-r

Bug 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

TS 4.7
TS 4.6

💻 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.

Metadata

Metadata

Assignees

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions