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!
I'd like to use top-level
awaitin a code sample:If I do so, I get the following error:
Adding these directives does not fix the error:
It would be nice if this worked!