TypeStrong / ts-node

TypeScript execution and REPL for node.js
https://typestrong.org/ts-node
MIT License
12.92k stars 532 forks source link

In REPL, can't access the previous line's return value via `_` #2087

Open Iwaslazkis opened 1 year ago

Iwaslazkis commented 1 year ago

Search Terms

REPL, Return Value, _

Expected Behavior

$ ts-node
> const foo = 123
undefined
> foo
123
> _
123
> "strings, like anything else, should work"
'strings, like anything else, should work'
> const bar = _
undefined
> bar
'strings, like anything else, would work'
> 

Actual Behavior

$ ts-node
> const foo = 123
undefined
> foo
123
> _
<repl>.ts:6:1 - error TS2304: Cannot find name '_'.

6 _
  ~

> "strings don't work either"
"strings don't work either"
> const bar = _
<repl>.ts:7:13 - error TS2304: Cannot find name '_'.

7 const bar = _
              ~

> bar
<repl>.ts:7:1 - error TS2304: Cannot find name 'bar'.

7 bar
  ~~~

> 

Steps to reproduce the problem

Open a ts-node REPL, execute a line of code, and on the next line the return value should be accessible via _, just like on the normal node REPL, as described here.

Minimal reproduction

Given this is happening in any ts-node REPL environment as far as I can tell (at least on the versions mentioned below), I'm not sure what exactly what a "minimal reproduction" would look like here. Please specify what you want me to include if you still want one though, and I'd be happy to oblige.

### Specifications