Skip to content

Support target/module tsconfig settings via directive #230

Description

@danvk

I'd like to use top-level await in a code sample:

export async function fetchPeak(peakId: string): Promise<MountainPeak>;
export async function fetchPeak(peakId: string): Promise<unknown> {
  return checkedFetchJSON(`/api/mountain-peaks/${peakId}`);  // OK
}

const denali = await fetchPeak('denali');
//    ^? const denali: MountainPeak

If I do so, I get the following error:

hide-unsafe-casts.asciidoc:134:16-21: Unexpected TypeScript error: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher.

Adding these directives does not fix the error:

// verifier:tsconfig:module=es2022
// verifier:tsconfig:target=es2017

It would be nice if this worked!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions