Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
teknsl opened this issue May 28, 2020 · 11 comments
Closed

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

teknsl opened this issue May 28, 2020 · 11 comments
Labels
bug Something isn't working correctly upstream Changes in upstream are required to solve these issues

Comments

@teknsl
Copy link

teknsl commented May 28, 2020

// 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)

@marcosc90
Copy link
Contributor

marcosc90 commented May 28, 2020

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();

@kitsonk
Copy link
Contributor

kitsonk commented May 28, 2020

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

@MarkTiedemann
Copy link
Contributor

@kitsonk You mentioned this issue before in #471, which is a general issue about top-level await. Might be good to keep this one open just for this specific issue.

@bartlomieju bartlomieju added bug Something isn't working correctly upstream Changes in upstream are required to solve these issues labels Jun 7, 2020
@jingkaimori
Copy link

this error disappear on deno 1.19.1, can this issue be closed?

@kitsonk kitsonk closed this as completed Mar 3, 2022
@soshimee
Copy link

soshimee commented May 9, 2022

Not fixed on Deno 1.20.3. At least on Windows.

@kitsonk
Copy link
Contributor

kitsonk commented May 9, 2022

@soshimee can you please provide a full reproduction and the full output of deno --version.

@MarkTiedemann
Copy link
Contributor

MarkTiedemann commented May 9, 2022

Can confirm. This never worked.

With v1.19.1:

C:\dev\test>.\deno.exe run repro.ts
error: TS2304 [ERROR]: Cannot find name 'await'.
await (async () => 1)();
~~~~~
    at file:///C:/dev/test/repro.ts:1:1

With v1.21.2:

C:\dev\test>.\deno.exe run repro.ts
Check file:///C:/dev/test/repro.ts
error: TS2311 [ERROR]: Cannot find name 'await'. Did you mean to write this in an async function?
await (async () => 1)();
~~~~~
    at file:///C:/dev/test/repro.ts:1:1

repro.ts containing await (async () => 1)();.

@soshimee
Copy link

soshimee commented May 9, 2022

@kitsonk

deno 1.20.3 (release, x86_64-pc-windows-msvc)
v8 10.0.139.6
typescript 4.6.2

@nhrones
Copy link

nhrones commented May 9, 2022

works for me

deno 1.21.2 (release, x86_64-pc-windows-msvc)
v8 10.0.139.17
typescript 4.6.2
\C:\Users\nhron> deno
Deno 1.21.2
exit using ctrl+d or close()
> await (async () => 1)();
1
>

@MierenManz
Copy link

the problem is not the code execution but the typescript error it raises when trying to typecheck the file

@kitsonk kitsonk reopened this May 9, 2022
@nayeemrmn
Copy link
Collaborator

Fixed by #14875.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly upstream Changes in upstream are required to solve these issues
Projects
None yet
Development

No branches or pull requests

10 participants