Introduction to TypeScript

Last Updated : 11 Aug, 2026

TypeScript is a statically typed superset of JavaScript that transpiles to JavaScript, making code more reliable and easier to maintain.

  • Adds static typing and modern language features.
  • Detects errors during development.
  • Improves code quality and developer productivity.
hello_world2

"Hello, World!" Program in TypeScript

A "Hello, World!" program is the simplest way to get started with any programming language. Here’s how you can write one using TypeScript.

In Browser (via Compilation)

Create a file hello.ts:

JavaScript
// This is our first TypeScript program
let message: string = "Hello, World!";
console.log(message);

Now compile it into JavaScript using:

npx tsc hello.ts

This will generate a hello.js file, which can then be included in your HTML.

HTML
<html>
<body>
<h1>
   Check the console for the message!
        </h1>
<script src="hello.js">
</script>
</body>
</html>

In Node.js Console: Simply run the compiled JavaScript:

node hello.js

Output:

Hello, World!

Comments

Comments are notes in your code that the TypeScript interpreter ignores. They’re great for explaining what your code does or for testing purposes.

  • Single-line comment: Starts with //
JavaScript
// This is a single-line comment
  • Multi-line comment: Enclosed in /* */
JavaScript
/* This is a multi-line comment
   spanning multiple lines */

Client Side and Server Side Nature of TypeScript

TypeScript’s flexibility extends to both the client-side and server-side, allowing developers to create complete, scalable applications. Here’s how it functions in each environment:

introduction_to_typescript

Client-Side

  • Used for controlling the browser and its DOM (Document Object Model).
  • Handles user events like clicks, form inputs, and rendering dynamic content.
  • Angular, React, Vue, Next.js, Remix, Astro, and other modern frameworks provide excellent TypeScript support.

Server-Side

  • Used for interacting with databases, handling APIs, file manipulation, and generating responses.
  • Node.js with TypeScript, along with frameworks like Express, Nest.js, Fastify is widely used to build type-safe backend applications.
  • Type definitions help catch errors early and make server-side code more reliable and maintainable.

Must Read: JavaScript Vs TypeScript

Comment

Explore