镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Directly destructuring awaited generic collapses to any #29414

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 !!!!!!!!!!!
}

Activity

  1. RyanCavanaugh commented on Jan 14, 2019

    @RyanCavanaugh
    Member

    Simpler repro

    declare function post<T = { result: string }>(): T;
    
    function bar() {
      const response = post();
      const { result } = response;
    }
    
    function baz() {
      const { result } = post();
      result.subst_r; // should be error
    }
  2. weswigham commented on Jul 8, 2020

    @weswigham
    Member

    This is fixed in our latest nightlies, by #39081 (#38969 was a dupe of this, looks like)

  3. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions