question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove top-level async function in TS script examples

See original GitHub issue

TS now supports top-level await: https://twitter.com/typescript/status/1230629807991341058?s=12

We should consider removing the top-level async main function in the TS script example.

image

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
timsuchanekcommented, Apr 22, 2020

Update about top-level await: I just talked to Andrew from the TypeScript team, and it looks like it’s not yet what we think it is.

So what this PR just did, is making sure, that top level await is “not transformed” anymore. That means, if you have top-level await in your TS code, it will end up in the generated JS code.

In order to use it today, you need to provide the v8 flag --harmony-top-level-await. Another option he mentioned, is that you might get it running with --module=systemjs, which we can investigate, but it doesn’t seem like an established thing yet, that we should recommend as the default.

So it seems like Node is just not ready yet.

2reactions
schicklingcommented, Mar 2, 2020

https://github.com/prisma/prisma-client-js/issues/540 is related as it makes calling prisma.disconnect() optional.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - How can I use async/await at the top level?
Use top-level await (proposal, MDN; ES2022, broadly supported in modern environments) that allows top-level use of await in a module.
Read more >
Typescript top level await - YouTube
Typescript top level await let you write await directly without the need of an async function wrapper. This will allow you to write...
Read more >
await - JavaScript - MDN Web Docs
The await operator is used to wait for a Promise and get its fulfillment value. It can only be used inside an async...
Read more >
Use Promise.all to Stop Async/Await from Blocking Execution ...
Heads up! There are ways to clean this up, such as pulling out the functions passed to .then into to top-level scope and...
Read more >
TypeScript's New Top-Level Await - Better Programming
In this article, I want to show you that it is possible to finally use top-level await instead of wrapping it between an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found