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: