Skip to content

async function return expressions are not contextually typed #36154

Closed
@falsandtru

Description

@falsandtru

TypeScript Version: 3.7.x-dev.20200111

Search Terms:

Code

declare function f(cb: (v: boolean) => [0] | PromiseLike<[0]>): void;
f(v => v ? [0] : Promise.reject()); // ok
f(async v => v ? [0] : Promise.reject()); // error

Expected behavior:
pass
Actual behavior:

Type 'Promise<number[]>' is not assignable to type '[0] | PromiseLike<[0]>'.
  Type 'Promise<number[]>' is not assignable to type 'PromiseLike<[0]>'.
    Types of property 'then' are incompatible.
      Type '<TResult1 = number[], TResult2 = never>(onfulfilled?: ((value: number[]) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<...>) | null | undefined) => Promise<...>' is not assignable to type '<TResult1 = [0], TResult2 = never>(onfulfilled?: ((value: [0]) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => PromiseLike<...>'.
        Types of parameters 'onfulfilled' and 'onfulfilled' are incompatible.
          Types of parameters 'value' and 'value' are incompatible.
            Property '0' is missing in type 'number[]' but required in type '[0]'.(2322)

Playground Link: http://www.typescriptlang.org/play/index.html?ts=3.8.0-dev.20200111#code/CYUwxgNghgTiAEAzArgOzAFwJYHtVIAowAjALngIDdziccIQpUBKeAXgD54BtABgF14AH3gAFGDgC2WAM4gAMlgDWIADx9+HZuUo4swANwAoRFXZdK8APw8B8cuKmyQAOjgArcBgLNmx01AyAJ7o8JacYda2gg4S0nJuIJ6YPn5AA

Related Issues:

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Contextual TypesThe issue relates to contextual types

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions