Skip to content

3.7.2 Promise.all infers base type of interfaces rather than actual interface #34937

@thaoula

Description

@thaoula

TypeScript 3.7.2
Playground link

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,
    "experimentalDecorators": false,
    "emitDecoratorMetadata": false,
    "target": "ES2017",
    "module": "ESNext"
  }
}

Input:

interface QuoteFilter {
    _id: string;
}

interface QuoteFilterAdvanced extends QuoteFilter {
    name: string;
}

function getQuoteFilters(): Promise<QuoteFilter[]> {
    return new Promise<QuoteFilter[]>(
        (resolve, reject) => {
            resolve([
               { _id: 'Test' }
            ]);
        });
}

function getQuoteFiltersAdvanced(): Promise<QuoteFilterAdvanced[]> {
    return new Promise<QuoteFilterAdvanced[]>(
        (resolve, reject) => {
            resolve([
               { _id: 'Test', name: 'Test' }
            ]);
        });
}

async() => {
    const [filters, advanced] = await Promise.all([
        getQuoteFilters(),
        getQuoteFiltersAdvanced()
    ]);
}

Output:

"use strict";
function getQuoteFilters() {
    return new Promise((resolve, reject) => {
        resolve([
            { _id: 'Test' }
        ]);
    });
}
function getQuoteFiltersAdvanced() {
    return new Promise((resolve, reject) => {
        resolve([
            { _id: 'Test', name: 'Test' }
        ]);
    });
}
async () => {
    const [filters, advanced] = await Promise.all([
        getQuoteFilters(),
        getQuoteFiltersAdvanced()
    ]);
};

Expected behavior:
I am expecting the advanced variable to be an array of QuoteFilterAdvanced rather than QuoteFilter.

This was correctly inferred in Typescript 3.6.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions