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

Top level await breaks on parentheses #3391

Closed
rsp opened this issue Nov 21, 2019 · 4 comments · Fixed by #4100
Closed

Top level await breaks on parentheses #3391

rsp opened this issue Nov 21, 2019 · 4 comments · Fixed by #4100

Comments

@rsp
Copy link
Contributor

rsp commented Nov 21, 2019

This is fine:

const x = await 1;

This is not:

const x = await (1 + 2);

It exits with: error TS2304: Cannot find name 'await'.

$ deno -v
deno: 0.24.0
v8: 8.0.192
typescript: 3.7.2

The above is the most minimal example that shows this.

More realistic use case - if I have a promise p like this:

const p = Promise.resolve({ x: Promise.resolve(1) });

I cannot get to the value 1 in one step:

const val = await (await p).x;

It exits with: error TS2304: Cannot find name 'await'.

I have to do it in two steps:

const tmp = (await p).x;
const val = await tmp;

I suppose that those are the parentheses (maybe the compiler thinks it is a function call?) but I can be wrong here.

@kevinkassimo
Copy link
Contributor

kevinkassimo commented Nov 21, 2019

This seems to be TS only. JS works fine

Looks like we have to wait for TypeScript 3.8 to get full support from TS on TLA

@kitsonk
Copy link
Contributor

kitsonk commented Nov 22, 2019

Agreed, we can't just safely ignore TS2304 as it might ignore other things incorrectly, and adding logic to introspect the error message would be a bit of a slippery slope for something we are already hacking around.

@ry
Copy link
Member

ry commented Nov 22, 2019

We just have to wait for TS to fix it.

@rsp
Copy link
Contributor Author

rsp commented Nov 22, 2019

kitsonk added a commit to kitsonk/deno that referenced this issue Feb 24, 2020
In regards to top-level-await, TypeScript will throw if the input does
not look like a module (as top-level-await is not supported in scripts).
TypeScript recommends adding `export {};` to the file, which is the
current idomatic way of identifying a module as a module that otherwise
has no imports or exports.

Resolves denoland#3937
Resolves denoland#3301
Resolves denoland#3391
@ry ry closed this as completed in #4100 Feb 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants