-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Directly destructuring awaited generic collapses to any #29414
Copy link
Copy link
Closed
Description
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 !!!!!!!!!!!
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScript