ts-node is an npm package which allows the user to run typescript files directly, without the need for precompilation using tsc . It also provides REPL.
npm install -g ts-node
npm install -g typescript
To execute a script named main.ts, run
ts-node main.ts
console.log("Hello world");
- $
ts-node main.ts
Hello world
To run REPL run command ts-node
- Example usage
$ `ts-node`
> const sum = (a, b): number => a + b;
> `undefined`
> `sum(2, 2)`
> 4
> .exit
To exit REPL use command .exit
or press CTRL+C
twice.