Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
OmgImAlexis opened this issue Apr 9, 2020 · 1 comment
Closed

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

OmgImAlexis opened this issue Apr 9, 2020 · 1 comment
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed

Comments

@OmgImAlexis
Copy link

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

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Jun 1, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.0 milestone Jun 1, 2020
@rbuckton rbuckton added Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Bug A bug in TypeScript and removed Needs Investigation This issue needs a team member to investigate its status. labels Jun 30, 2020
@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label Aug 31, 2020
@RyanCavanaugh RyanCavanaugh added Design Limitation Constraints of the existing architecture prevent this from being fixed and removed Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Rescheduled This issue was previously scheduled to an earlier milestone labels Feb 4, 2022
@RyanCavanaugh RyanCavanaugh removed this from the TypeScript 4.6.1 milestone Feb 4, 2022
@RyanCavanaugh
Copy link
Member

It doesn't look like we have any straightforward fixes available at this time. Closing as Design Limitation until we have more motivating scenarios to figure out a possible larger solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants