Run TypeScript files directly without (manually) transpiling them to JavaScript.
ts-runner requires nodejs.
Clone repo and set ts-runner executable
git clone https://github.com/tinosteinort/ts-runner
cd ts-runner
chmod +x ts-runner
ts-runner is used as interpreter for the TypeScript file, so it must be
referenced in the first line of the file. If the target script file is
in the same directory as the ts-runner, it is enough to add
#!ts-runner
If ts-runner is in your home folder you can add
#!~/ts-runner
If ts-runner is on the $PATH you can add
#!/usr/bin/env ts-runner
... and so on...
Create file examplescript.ts and add the following content:
#!ts-runner
const value: string = 'World';
console.log('Hello', value);
Set the script file executable:
chmod +x examplescript.ts
Now, you are able to execute the script. Type in the terminal:
./examplescript.ts
There are other tools, that do the same: see ts-node