Hello World in TypeScript
Our first program will print the classic “hello world” message. Here’s the full source code.
To run the program, you will need to compile the TypeScript code into JavaScript and then execute it using Node.js.
First, install TypeScript if you don’t have it:
Then, compile the TypeScript code into JavaScript:
Now, you can run the resulting JavaScript file:
Sometimes we’ll want to build our programs into a single file. TypeScript compilation achieves this by producing an equivalent .js
file.
First, compile the TypeScript file:
We can then execute the compiled JavaScript file directly using Node.js.
Now that we can run and build basic TypeScript programs, let’s learn more about the language.