Skip to content

Unnecessary, misleading expansion lines for a keyof generic used in a template literalΒ #47668

Description

Bug Report

πŸ”Ž Search Terms

keyof generic template literal type symbol

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about generics and assignability

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type KeyGet<T> = `get${keyof T}`;

πŸ™ Actual behavior

Notice the fourth Type 'keyof T' line onward. Seems unnecesary?

Type 'keyof T' is not assignable to type 'string | number | bigint | boolean | null | undefined'.
  Type 'string | number | symbol' is not assignable to type 'string | number | bigint | boolean | null | undefined'.
    Type 'symbol' is not assignable to type 'string | number | bigint | boolean | null | undefined'.
      Type 'keyof T' is not assignable to type 'number'.
        Type 'string | number | symbol' is not assignable to type 'number'.
          Type 'string' is not assignable to type 'number'.

πŸ™‚ Expected behavior

Type 'keyof T' is not assignable to type 'string | number | bigint | boolean | null | undefined'.
  Type 'string | number | symbol' is not assignable to type 'string | number | bigint | boolean | null | undefined'.
    Type 'symbol' is not assignable to type 'string | number | bigint | boolean | null | undefined'.

Note that if you replace keyof T with string | number | symbol, the error message is the expected behavior. [playground link with replacement]

type KeyGet<T> = `get${string | number | symbol}`;
Type 'string | number | symbol' is not assignable to type 'string | number | bigint | boolean | null | undefined'.
  Type 'symbol' is not assignable to type 'string | number | bigint | boolean | null | undefined'.

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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