Hello World in TypeScript
Last Updated :
06 Sep, 2025
The TypeScript Hello World program is a simple tradition used by programmers to learn the new syntax of the language. It involves displaying the text "Hello, World!" on the screen. This basic exercise helps you understand how to write TypeScript code, compile it to JavaScript, and run it in different environments.
How to Write a Simple TypeScript Hello World Program
TypeScript is a superset of JavaScript, which means any valid JavaScript is also valid TypeScript. The main difference is that TypeScript adds optional static typing and modern features to JavaScript. Let’s see how to write a Hello World program in TypeScript.
1. Using Node.js and the Terminal
One of the easiest ways to run TypeScript code is by using Node.js. You need to install Node.js and TypeScript first.
Steps:
- Install Node.js from nodejs.org.
- Install TypeScript globally by running:
npm install -g typescript
- Create a new file called hello.ts and write the following code:
JavaScript
console.log("Hello, World!");
- Compile the TypeScript file to JavaScript using the TypeScript compiler:
tsc hello.ts
- Run the compiled JavaScript file with Node.js:
node hello.js
You should see:
Hello, World!
2. Using an HTML File
TypeScript can also be used in web pages, but it must be compiled into JavaScript first.
Steps:
1. Create a file called hello.ts with the following code:
JavaScript
const message: string = "Hello, World!";
alert(message);
2. Compile it to JavaScript:
tsc hello.ts
3. Create an HTML file called index.html and include the compiled JavaScript file:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello World in TypeScript</title>
</head>
<body>
<script src="hello.js"></script>
</body>
</html>
4. Open the HTML file in a browser, and you will see an alert displaying "Hello, World!".
Explore
TypeScript Tutorial
8 min read
TypeScript Basics
TypeScript primitive types
TypeScript Object types
TypeScript other types
TypeScript combining types
TypeScript Assertions
TypeScript Functions
TypeScript interfaces and aliases
TypeScript classes