Skip to content

3.7-beta regression: Promise.all wrongly adds undefined type #33752

@Swatinem

Description

@Swatinem

TypeScript Version: 3.7.0-beta

Search Terms:

promise all

Code

interface A {
  a: string
}
interface B {
  b: string
}
async function main(): Promise<A> {
  const [a, b] = await Promise.all([
    Promise.resolve({a: "a"} as A),
    Promise.resolve({b: "b"} as B | undefined), // <- the `| undefined` here is the problem
  ]);
  return a; // <- a has type `A | undefined`, but should be `A`
}

Expected behavior:

This is a regression from 3.6.3, where the return tuple of Promise.all is correctly inferred.

Actual behavior:

A | undefined bound of a different tuple member also adds a | undefined bound on a different unrelated return value of Promise.all.

Playground Link:

https://www.typescriptlang.org/play/?ts=3.7-Beta#code/JYOwLgpgTgZghgYwgAgILIN4ChnLgLmQGcwpQBzLAXy1ElkRQCFMdkAjQkskSmuIgE8QCZDACuIsMAD2IZAFs4oABQBKQgAUoMhcCIQAPKgB8rXAjklkAbTgAaDgF1kAXjwB3ZWGTbd+iAA6OAAbEJUbNlw-PQNAqAgiGRCANwgVDAJkACI4bKo8IjQ1eyjfHVighKTU9IxOHPZ8wuQWAB9kSQATCBhQCC6S5AB6YeRDAFpkMAALFAADDu7e-q755DmE5H1pueQABx12EIgFNic1AG42BLBxKHk4S5GxybwNgWnBfYX0JZAen0QAN5o52OIfEQZjJxCEuhxfvNqEA

Related Issues:

Maybe #33707 ?

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions