privatenumber / tsx

⚡️ TypeScript Execute | The easiest way to run TypeScript in Node.js
https://tsx.is
MIT License
9.43k stars 144 forks source link

Multiline input in Typescript REPL #516

Closed 500-internal-server-error closed 6 months ago

500-internal-server-error commented 6 months ago

Acknowledgements

Minimal reproduction URL

Not applicable as a file

Version

v4.7.1

Node.js version

v21.7.1

Package manager

N/A

Operating system

Windows

Problem & expected behavior (under 200 words)

tsx accepts Typescript single line inputs, but not multiline inputs, unlike ts-node.

ts-node:

username@localhost:~ $ ts-node
> function stringify(num: number): string { return "" + num; }
undefined
> function unstringify(num: string): number {
... return +num;
... }
undefined
>

tsx:

username@localhost:~ $ tsx
Welcome to Node.js v21.7.1.
Type ".help" for more information.
> function stringify(num: number): string { return "" + num; }
undefined
> function unstringify(num: string): number {
function unstringify(num: string): number {
                        ^

Uncaught SyntaxError: Unexpected token ':'
>

This issue is not reproducible with the StackBlitz template provided, since it involves interactive use of the CLI rather than running a file.

Contributions