Skip to content

Top-level await support in REPL #245

Closed
@aseemk

Description

@aseemk

Hey there,

Great work on ts-node! I just looked through the code a bit, and you all have clearly put a lot of thought and time into it. Thank you.

One request: I love using the REPL for quick exploration/experimentation/learning. And that often involves async steps, e.g. DB queries or API requests.

Before TypeScript, we used to use Streamline.js, and I loved that its REPL supported making async calls and awaiting their responses:

$ _node
_node> fs.stat('/dev/null', _)
{ dev: 1011986504, ... }
_node> r.get('https://httpbin.org/ip', _).body
'{\n  "origin": "1.2.3.4"\n}\n'
_node> ...

I understand that TypeScript and ES6/7 as languages don't allow top-level await in modules, but would you be open to supporting that in the REPL?

The way the Streamline REPL does it is simply by wrapping the code in an async IIFE, and only calling the REPL eval callback once the async IIFE finishes:

https://github.com/Sage/streamlinejs/blob/v2.0.13/lib/repl.js#L23-L42

Thank you in advance for the consideration! Cheers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions