Skip to content

Incorrect substitution on index access with generic key type on generic mapped type with key remapping  #47794

@LANGERGabrielle

Description

@LANGERGabrielle

Bug Report

As soon as this bug is approved I can open the PR with my fix.
This seems somewhat related to #44115

🔎 Search Terms

mapped remapping

🕗 Version & Regression Information

  • This bug is present since 4.1.0, when remapping was introduced

⏯ Playground Link

Playground link for ^4.4
Playground link for ^4.1

💻 Code

type Foo<T extends string> = {
    [RemappedT in T as `get${RemappedT}`]: RemappedT;
};
const get = <T extends string>(t: T, foo: Foo<T>): T => foo[`get${t}`]; // Type '`get${T}`' is not assignable to type 'T'

🙁 Actual behavior

When resolving the type of foo[`get${t}`], Typescript substitutes RemappedT with `get${T}`. foo[`get${t}`] ends up resolving to `get${T}`.

🙂 Expected behavior

Typescript should resolve foo[`get${t}`] with the type T.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFix AvailableA PR has been opened for this issueHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions