Skip to content

Destructuring property ends up as any when using { [key]:x} = aObject #20725

Closed
@theduffmtl

Description

@theduffmtl

TypeScript Version: 2.7.0-dev.201xxxxx

Code

interface Model {
    '0': number
}

const key = '0';
const keyLiteral: '0' = '0';

const myModel = {
    '0': 9
}
const { [key]: iendupAsAny } = myModel;

const { [keyLiteral]: iEndupAnyAsWell } = myModel;

const { ['0']: meImWellTyped } = myModel;

Expected behavior:
I would expect the 3 fields to be typed as number or a typescript error since noImplicitAny is true

Actual behavior:

the first 2 end up as any

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions