Typescript sometimes has a reputation for being difficult to get started with. Modern tooling has really improved this situation and it is now very easy to create a new project and get up and running in no time.
Create a new project (in 30 seconds)
In a terminal on Mac OSX or Linux create a new directory and navigate to it using this command:
You need a
file to run a typescript project. Use
to create one:
The output shows a newly created
compiler and the loader
as development dependencies.
The shell output shows the installed dependencies (with your version instead)
Next you can create a
file using typescript's
A success message is shown in the terminal:
Create a typescript file
Now we can create a simple typescript file called
Run the script
You can run typescript using NodeJS with the
Run your script like so:
The output shows our message:
You can now write and run typescript files easily. To make run commands easier try adding the scripts to the package.json file:
Then run your script using
Why use Typescript?