I have a .mjs file:
console.log(await foo())
I want this code to be type-checked (there's more in this file of course ;) ) so I add // @ts-check
// @ts-check
console.log(await foo())
but now tsserver shows me this error:
Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', or 'nodenext', and the 'target' option is set to 'es2017' or higher.
How can I fix this?
Solutions I have thought of:
- adding a
jsconfig.jsonto my project
- I don't want any extra files in my project
- Don't use top-level
await
- In this case I could just do
foo().then(console.log)
Ideal solution
A comment I can place next to @ts-check like
// @ts-check
// @ts-module es2022
// @ts-target es2022
console.log(await foo())