Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
theduffmtl opened this issue Dec 15, 2017 · 3 comments
Closed
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@theduffmtl
Copy link

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

@RyanCavanaugh RyanCavanaugh added Breaking Change Would introduce errors in existing code Bug A bug in TypeScript labels Dec 19, 2017
@Jessidhia
Copy link

This looks related to, but not quite the same as #16789

@mhegazy mhegazy added this to the TypeScript 2.7.1 milestone Jan 9, 2018
@sandersn
Copy link
Member

sandersn commented Jan 9, 2018

Fixed by #21070

@mhegazy
Copy link
Contributor

mhegazy commented Apr 25, 2018

The examples in the OP should be fixed in latest.

@mhegazy mhegazy closed this as completed Apr 25, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

5 participants