Skip to content

Top level await breaks on parentheses #3391

@rsp

Description

@rsp

This is fine:

const x = await 1;

This is not:

const x = await (1 + 2);

It exits with: error TS2304: Cannot find name 'await'.

$ deno -v
deno: 0.24.0
v8: 8.0.192
typescript: 3.7.2

The above is the most minimal example that shows this.

More realistic use case - if I have a promise p like this:

const p = Promise.resolve({ x: Promise.resolve(1) });

I cannot get to the value 1 in one step:

const val = await (await p).x;

It exits with: error TS2304: Cannot find name 'await'.

I have to do it in two steps:

const tmp = (await p).x;
const val = await tmp;

I suppose that those are the parentheses (maybe the compiler thinks it is a function call?) but I can be wrong here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions