tsconfig.jsonのtargetに注意しないと、new AsyncFunction()内でawaitを使った文字列を実行できない
#AsyncFunction #TypeScript #top-level_await #エラー対処
現象
Top-level awaitがしたくてnew AsyncFuction()を使うときに、tsconfig.jsonが"target": "es6",だと「[error]await is only valid in async function」というエラーが出る。
対処法
少なくとも「"target": "es2018",」だとうまくいく。
関連
この(feat: support top-level await · nwtgck/actions-comment-run@3dd5e59)実装をするときに分かったこと。
ここで()、どうようのことをやっているgithub-scriptの実装を観察して、上記のtsconfig.jsonが原因であることがわかった。