Skip to content

Destructuring with computed property loses type information #23257

@ajafff

Description

@ajafff

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

Metadata

Metadata

Assignees

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