Skip to content

Unexpected compile / type error when using Promise.all #35136

Closed
@jeremywen3

Description

@jeremywen3

TypeScript Version: 3.7.2

Search Terms:

  • Promise.all typing

Code

index.ts

type RandomType = {};

const getRandomValue = async (): Promise<RandomType> => {
    return {};
};

const getResults = async (): Promise<{ data: string[] }> => {
    return { data: ['a', 'b', 'c'] };
};

const run = async () => {
    const [random, { data }] = await Promise.all([getRandomValue(), getResults()]);
    console.log(random, data);
};

run();

tsconfig.json

{
    "compilerOptions": {
        "target": "esnext",
        "lib": ["esnext", "dom"]
    },
    "exclude": ["node_modules"],
    "include": ["./**/*.ts"]
}

Expected behavior:
Compiles successfully.

Actual behavior:
Compile error: "Property 'data' does not exist on type 'RandomType'."

Seems to still compile the js file even though it shows a compile error.

Does not run with ts-node though.

Playground Link:
http://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=13&pc=31#

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdFix 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