Skip to content

[Bug Report] Wrong keyof type with string index signature #39543

Description

@meteorlxy

TypeScript Version: 3.9.x

Search Terms: keyof, index signature

Code

interfaceTest1{[key: string]: string;}typeKeyofTest1=keyofTest1interfaceTest2{[key: number]: string;}typeKeyofTest2=keyofTest2

Expected behavior:

  • KeyofTest1 should be string
  • KeyofTest2 should be number

Actual behavior:

  • KeyofTest1 is string | number (wrong)
  • KeyofTest2 is number (correct)

Playground Link:https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=12&pc=1#code/JYOwLgpgTgZghgYwgAgCoQM5gIzIN4BQyxyA2gNYQCeAXMllKAOYC6dDzA3AQL4EFgqABxQBpagHsY6LLgC8ySlSlpMOfqEixEKGWABM+IiQrU6IAK4BbAEbQ29MIxBNufAcLGTpawwqUqevoEQA

Related Issues:

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions