Skip to content

Regression in type inference for Promise.all() #28792

Closed
@Tatamo

Description

@Tatamo

TypeScript Version: 3.2.1 & 3.3.0-dev.20181201

Search Terms:
type inference, promise, tuple

Code

async function f(x: number): Promise<number>{
    return x + 1;
}

async function g(s: string): Promise<string>{
    return s + "\n";
}

async function h(): Promise<string> {
    const [a, b] = await Promise.all([f(1), g("x")]).catch(() => [null, null]);
    if (a === null || b === null) throw new Error();
    return b.trim();
}

Expected behavior:
no compile error, as in TS3.1

Actual behavior:

test.ts:12:12 - error TS2339: Property 'trim' does not exist on type 'string | number'.
  Property 'trim' does not exist on type 'number'.

12   return b.trim();
              ~~~~

In TS3.1:

a: number | null
b: string | null

In TS3.2:

a: string | number | null
b: string | number | null

Playground Link:
here
(Enable strictNullChecks to reproduce it)

Related Issues:

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions