Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JoshuaKGoldberg opened this issue Jan 30, 2022 · 1 comment Β· Fixed by #47738
Closed
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Help Wanted You can do this
Milestone

Comments

@JoshuaKGoldberg
Copy link
Contributor

JoshuaKGoldberg commented Jan 30, 2022

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'.
@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Feb 1, 2022
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Feb 1, 2022
@RyanCavanaugh
Copy link
Member

Weird

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants