Skip to content

Promise.then does not accept callback that returns T | Promise<S> #15599

Closed
@rkirov

Description

@rkirov

TypeScript Version: 2.3.1

Code

declare let p: Promise<void>;
declare let p2: Promise<string>;

let p3 = p.then(() => Math.random() ? 0 : p2);

Expected behavior:
Code is accepted and type of p3 is Promise<string|number>.

Actual behavior:
Type Error: Argument of type '() => Promise<string> | 0' is not assignable to parameter of type '(value: void) => string | PromiseLike<string>'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions