TypeScript Version: 3.9.x
Search Terms: keyof, index signature
Code
interfaceTest1{[key: string]: string;}typeKeyofTest1=keyofTest1interfaceTest2{[key: number]: string;}typeKeyofTest2=keyofTest2Expected behavior:
KeyofTest1 should be stringKeyofTest2 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:
TypeScript Version: 3.9.x
Search Terms: keyof, index signature
Code
Expected behavior:
KeyofTest1should bestringKeyofTest2should benumberActual behavior:
KeyofTest1isstring | number(wrong)KeyofTest2isnumber(correct)Playground Link:https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=12&pc=1#code/JYOwLgpgTgZghgYwgAgCoQM5gIzIN4BQyxyA2gNYQCeAXMllKAOYC6dDzA3AQL4EFgqABxQBpagHsY6LLgC8ySlSlpMOfqEixEKGWABM+IiQrU6IAK4BbAEbQ29MIxBNufAcLGTpawwqUqevoEQA
Related Issues: