Skip to content

Destructuring with computed property loses type information #23257

New issue

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

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

Already on GitHub? Sign in to your account

Closed
ajafff opened this issue Apr 8, 2018 · 0 comments
Closed

Destructuring with computed property loses type information #23257

ajafff opened this issue Apr 8, 2018 · 0 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@ajafff
Copy link
Contributor

ajafff commented Apr 8, 2018

TypeScript Version: 2.9.0-dev.20180407

Search Terms: destructuring computed

Code

let { [Symbol.iterator]: destructured } = []; // destructured is any
let elementAccess = [][Symbol.iterator]; // elementAccess is type () => IterableIterator<never>

declare function get<T>(): T;

let { [get<'prop'>()]: computed } = get<{ prop: string }>(); // computed is any
let { prop } = get<{ prop: string }>(); // prop is string

Expected behavior:
destructured has the same type as elementAccess; computed has the same type as prop.

Actual behavior:
Destructuring with computed property always results in any.

Playground Link: http://www.typescriptlang.org/play/#src=let%20%7B%20%5BSymbol.iterator%5D%3A%20destructured%20%7D%20%3D%20%5B%5D%3B%0Alet%20elementAccess%20%3D%20%5B%5D%5BSymbol.iterator%5D%3B%0A%0Adeclare%20function%20get%3CT%3E()%3A%20T%3B%0A%0Alet%20%7B%20%5Bget%3C'prop'%3E()%5D%3A%20computed%20%7D%20%3D%20get%3C%7B%20prop%3A%20string%20%7D%3E()%3B%0Alet%20%7B%20prop%20%7D%20%3D%20get%3C%7B%20prop%3A%20string%20%7D%3E()%3B

Related Issues:
#17566 but that one is only about index signatures

@mhegazy mhegazy added the Bug A bug in TypeScript label Apr 9, 2018
@mhegazy mhegazy added this to the TypeScript 2.9 milestone Apr 9, 2018
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Apr 11, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants