Skip to content

ReplService.evalCode does not contribute to TypeScript's view of the scope #1764

Closed
@abextm

Description

@abextm

Expected Behavior

Executing code with evalCode to be equivalent to typing some code into the REPL's stdin

Actual Behavior

The REPL believes any declared variables are simultaneously not declared and already declared

Steps to reproduce the problem

const tsNode = require("ts-node");

let repl = tsNode.createRepl();
let service = tsNode.create({...repl.evalAwarePartialHost});
repl.setService(service);
repl.start();

repl.evalCode(`let foo = "bar"; console.log(foo);`);

Observe the code has been executed as bar is printed to stdout.

Enter foo into stdin, incorrectly giving
<repl>.ts:5:1 - error TS2304: Cannot find name 'foo'.
(should print bar)

Enter let foo = "baz"; into stdin giving the correct error, but with the wrong source text

<repl>.ts:1
"use strict"; void 0;
^

Uncaught SyntaxError: Identifier 'foo' has already been declared

Specifications

ts-node v10.7.0
node v18.1.0
compiler v4.6.4
  • Operating system and version:
    Arch Linux

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