javascriptnode.jstypescriptread-eval-print-loopts-node

Evaluating typed expressions in interactive ts-node


I'd like to know how to evaluate a TypeScript typed expression using ts-node --interactive as a REPL. I'm using a Mac and have installed node v24.5.0 via brew, and I've installed ts-node v10.9.2 and typescript v5.9.2 via npm.

When I write an expression and press enter all I get is a pipe as output, and it's not clear what am I expected to do to evaluate the result:

> 1 + 1
|
|

I'm aware that I can start the REPL using ts-node --transpile-only --interactive and expression evaluation works, but then type checking is disabled and that's not what I need:

> const n: number = 'string';
undefined
> n
'string'

EDIT: As this appears to be a regression in Node, I've created a bug report for it: https://github.com/nodejs/node/issues/59501 .


Solution

  • ts-node is currently abandoned and not maintained, there may be existing problems with it that have no fix.

    The problem can be reproduced with the latest ts-node (10) and Node (24). The solution is to use the last version that didn't have REPL broken:

    npx -y ts-node@9
    

    Or downgrade Node to LTS (22).