Deno: await (async () => {})() :: Cannot find name 'await'.ts(2304)

Created on 28 May 2020  路  3Comments  路  Source: denoland/deno

// working
const asyncFunc = async () => {
    return someValue;
}
let someValue = await asyncFunc();

// prefered but not working
let someValue = await (async () => {
   return someValue
})();

syntactically it is correct, but still it returns error Cannot find name 'await'.ts(2304)

bug upstream 鈽濓笍

Most helpful comment

I thought we had an issue for it open here, but it is an upstream TypeScript bug. Ref: https://github.com/microsoft/TypeScript/issues/38483

All 3 comments

Note: It works perfectly fine with .js files, it's the TS compiler throwing that error.

Check: https://www.typescriptlang.org/play/?ssl=2&ssc=11&pln=2&pc=20#code/DYUwLgBAzg9gtiAagQ2AVxBAvBZB3ZAS0gApkoBPAOwGMISBKbAPggG8AoCbgJ3DR5UIAVg4BfBowDcQA

Seems to have to do with top-level await, since the following does not break (So don't know if it's a TS issue or Deno TS config)

async function get() {
  let someValue = await (async() => {
    return 5;
  })();
}

get();

I thought we had an issue for it open here, but it is an upstream TypeScript bug. Ref: https://github.com/microsoft/TypeScript/issues/38483

@kitsonk You mentioned this issue before in https://github.com/denoland/deno/issues/471, which is a general issue about top-level await. Might be good to keep this one open just for this specific issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ry picture ry  路  3Comments

justjavac picture justjavac  路  3Comments

CruxCv picture CruxCv  路  3Comments

zugende picture zugende  路  3Comments

kyeotic picture kyeotic  路  3Comments