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

extends causing string literal can't be used as index #54886

Open
troy351 opened this issue Jul 5, 2023 · 6 comments Β· May be fixed by #57113
Open

extends causing string literal can't be used as index #54886

troy351 opened this issue Jul 5, 2023 · 6 comments Β· May be fixed by #57113
Labels
Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone

Comments

@troy351
Copy link

troy351 commented Jul 5, 2023

Bug Report

πŸ”Ž Search Terms

cannot be used as an index type

πŸ•— Version & Regression Information

  • This changed between versions 4.9.5 and 5.0.4

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

interface Dict {
  foo: 1
  bar: 1
}

type A = Dict['foo'] // works

type F = 'foo'
type B = Dict[F] // works

type FF = 'foo' extends ('foo' | 'bar') ? 'foo' : never // in theory, FF === F
type C = Dict[FF] // not working, Type '"foo"' cannot be used as an index type.(2538)

πŸ™ Actual behavior

type C throws error

πŸ™‚ Expected behavior

no error

@jcalz
Copy link
Contributor

jcalz commented Jul 5, 2023

Could you please edit this to conform to the bug report template? I'd hate for this to be closed for not following the template when it looks like a real issue

@troy351
Copy link
Author

troy351 commented Jul 5, 2023

I just did

@RyanCavanaugh
Copy link
Member

What's the version of this code that you originally had?

@troy351
Copy link
Author

troy351 commented Jul 7, 2023

This is a testing code when I debugging a complicated generic type, and the generic type works.
I know this kind of code nearly won't happen in real world, but it's still a bug.

@RyanCavanaugh
Copy link
Member

Right, but I'd really like a "real" version so we can make a testcase in the PR

@troy351
Copy link
Author

troy351 commented Jul 7, 2023

Sorry, there is no "real" version. Maybe consider the provided playground code as real

@RyanCavanaugh RyanCavanaugh added the Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases label Jul 7, 2023
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Projects
None yet
3 participants