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:

Setup node

You need a file to run a typescript project. Use to create one:

The output shows a newly created file:

Install typescript

Next save compiler and the loader as development dependencies.

The shell output shows the installed dependencies (with your version instead)

Setup tsconfig

Next you can create a file using typescript's command:

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 loader. Run your script like so:

The output shows our message:

Next steps

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?

Typescript is a superset of standard Javascript that adds a powerful type system to the Javascript you already know. It is totally optionally but can dramatically reduce compile-time bugs and exceptions due to the information that type systems can provide to a compiler and the process of compiling the typescript into javascript before running it. This step provides an extra step of logic validation before running your javascript. TS-Node is a helpful tool for running the compilation step inside node itself so that you can skip the build stage. MailSlurp uses Typescript to create email testing APIs for NodeJS. Send and receive emails and attachments from test email accounts using MailSlurp for free!