Skip to content

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

Closed
@meteorlxy

Description

@meteorlxy

TypeScript Version: 3.9.x

Search Terms: keyof, index signature

Code

interface Test1 {
    [key: string]: string;
}

type KeyofTest1 = keyof Test1

interface Test2 {
    [key: number]: string;
}

type KeyofTest2 = keyof Test2

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:

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