Skip to content

Promise.all not removing never[] in catch narrowing #37856

Closed
@OmgImAlexis

Description

@OmgImAlexis

TypeScript Version: 3.8.3

Search Terms:

Expected behavior:
broken should have the same type as working.

Actual behavior:
broken has an added never[] type.

Related Issues:

Code

const gotoThen = Promise.resolve(123);
const gotoCatch = Promise.reject();

// const working: Promise<number[]>
const working = Promise.all([
    gotoThen
]).catch(() => [123]);

// const broken: Promise<never[] | number[]>
const broken = Promise.all([
    gotoCatch
]).catch(() => [456]);

// Promise { [ 123 ] } Promise { [ 456 ] }
console.log(working, broken);
Output
"use strict";
const gotoThen = Promise.resolve(123);
const gotoCatch = Promise.reject();
// const working: Promise<number[]>
const working = Promise.all([
    gotoThen
]).catch(() => [123]);
// const broken: Promise<never[] | number[]>
const broken = Promise.all([
    gotoCatch
]).catch(() => [456]);
// Promise { [ 123 ] } Promise { [ 456 ] }
console.log(working, broken);
Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "useDefineForClassFields": false,
    "alwaysStrict": true,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "downlevelIteration": false,
    "noEmitHelpers": false,
    "noLib": false,
    "noStrictGenericChecks": false,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "esModuleInterop": true,
    "preserveConstEnums": false,
    "removeComments": false,
    "skipLibCheck": false,
    "checkJs": false,
    "allowJs": false,
    "declaration": true,
    "experimentalDecorators": false,
    "emitDecoratorMetadata": false,
    "target": "ES2017",
    "module": "ESNext"
  }
}

Playground Link: Provided

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