TypeScript Version: 2.4.0
Code
declare const textMap: {[key: string]: string}
function getText (input: string) {
const {
[input]: rawText = input
} = textMap
// rawText inferred as 'any' and not 'string'
}
Expected behavior:
rawText to be inferred as string
Actual behavior:
rawText inferred as any
As this is a destructuring pattern, it is actually not possible at all to declare the type of rawText other than by making rawText a let declaration first and running an destructuring expression, or otherwise writing equivalent code that does not use destructuring.
let rawText: string
({[input]: rawText = input} = textMap)