Skip to content

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

Open
@troy351

Description

@troy351

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Possible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some cases

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions