TypeScript Tutorial

Lesson 1: Introduction to TypeScript

Start your TypeScript journey by understanding what TypeScript is, how it differs from JavaScript, and why modern developers use it for safer and more scalable applications.

What Is TypeScript?

TypeScript is a programming language developed by Microsoft. It is built on top of JavaScript, which means every valid JavaScript program is also valid TypeScript. The main advantage is that TypeScript adds static typing and useful developer tools.

This helps programmers write clearer code, catch mistakes earlier, and manage larger applications more confidently.

Note: TypeScript does not replace JavaScript. TypeScript code is compiled into standard JavaScript before it runs.

Why TypeScript Matters

  • It detects type-related mistakes before the program runs.
  • It improves readability and maintainability.
  • It gives better editor support such as autocomplete and error hints.
  • It is widely used in modern front-end and back-end development.

JavaScript vs TypeScript

JavaScript is flexible, but that flexibility can sometimes create bugs. TypeScript makes your intentions clearer by allowing you to define the expected type of data.

let message: string = "Hello";
message = "Welcome to TypeScript";

In the code above, the variable is explicitly declared as a string. If you try to assign a number, TypeScript will show an error.

How TypeScript Works

Browsers do not run TypeScript directly. You write code in files that end with .ts, then compile them into JavaScript files with the .js extension.

app.ts  →  app.js

Your First TypeScript Example

let userName: string = "Alicia";
let age: number = 24;
let isMember: boolean = true;

console.log(userName);
console.log(age);
console.log(isMember);

Summary

TypeScript is the natural next step for JavaScript developers who want safer, cleaner, and more maintainable code. It keeps JavaScript’s flexibility while adding structure and reliability.