Skip to content

Directly destructuring awaited generic collapses to any #29414

Closed
@JasonKleban

Description

@JasonKleban

New in 3.2.2(?) is this type mistake in baz() below. result should be destructured to having type string, but instead it is any even though the unabbreviated syntaxes work correctly.

type responseType = { result: string }

declare function post<T = responseType>(): Promise<T>;

async function foo() {
    const response = await post(); // response : responseType  OK
    const result = response.result; // result : string OK
}

async function bar() {
    const response = await post(); // response : responseType OK
    const { result } = response; // result : string OK
}

async function baz() {
    const { result } = await post(); // result : any !!!!!!!!!!!
}

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions