Skip to content

Remove extraneous top-level await requirement #37794

Closed
@Vandivier

Description

@Vandivier

This may be a bug, I'm not sure. So I'm submitting as a feature request.

Search Terms

await, top-level, disable rule

Suggestion

"isolatedModules": true, should not be required to remove top-level await error.

Use Cases

I'm scripting a very simple file I/O script using Deno. The script runs without issue. Full code is in the below example.

Even though it works, VS Code complains. I think the complaint is at the TS level and I can't ignore it as a specific error. I can ts-ignore line-by-line, but that's not satisfactory.

The error is 'await' expressions are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module.ts(1375)

Examples

const decoder = new TextDecoder("utf-8");
const data = await Deno.readFile("tsconfig.json"); // <!-- VS Code shouldn't have red squiggle here.
console.log(decoder.decode(data));

Checklist

I have no idea whether this feature meets the items in the checklist.

Related Issues

  1. [merged PR] Add top-level await for esnext and system modules #35813
  2. @ts-ignore for the block scope and imports #19573
  3. Top Level "for await" not supported, but should be #37402
  4. Support top level "for await of" #37424
  5. [closed] Top-level await error message is extremely unclear #36036

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions