TypeScript in Plain English
TypeScript is JavaScript with one major addition: static types. You can annotate variables, function parameters, and return values with type information, and TypeScript checks these types when you compile your code — before it ever runs in a browser.
// JavaScript — no type information
function add(a, b) {
return a + b;
}
add(5, "10"); // returns "510" — silent bug!
// TypeScript — types are checked at compile time
function add(a: number, b: number): number {
return a + b;
}
add(5, "10"); // ❌ Error: Argument of type 'string' is not assignable to parameter of type 'number'TypeScript doesn't replace JavaScript — it compiles down to regular JavaScript. Browsers never see TypeScript; they see the JavaScript that TypeScript produces.
Why the Industry Adopted TypeScript
TypeScript has become the dominant choice for professional JavaScript projects because it catches entire categories of bugs that are invisible in plain JavaScript. When you're working on a large codebase with multiple developers, knowing the exact shape of every object passed between functions prevents hours of debugging. Your editor also gains powerful autocomplete because TypeScript tells it exactly what properties and methods exist on any value.
As of 2024, TypeScript is used by the majority of major JavaScript projects — React, Angular, Next.js, Node.js, and virtually every serious open-source library either ships TypeScript types or is written in TypeScript. Knowing TypeScript is increasingly a baseline expectation for mid-level and senior roles.
Essential TypeScript Syntax
// Basic types
let name: string = "Alex";
let age: number = 25;
let isActive: boolean = true;
let items: string[] = ["a", "b"];
let anything: any = "avoid this"; // escape hatch — use sparingly
// Interfaces — shape of an object
interface User {
id: number;
name: string;
email: string;
role?: string; // ? means optional
}
// Function types
function greet(user: User): string {
return `Hello, ${user.name}`;
}
// Union types
type Status = "pending" | "active" | "inactive";
let userStatus: Status = "active";
// userStatus = "deleted"; // ❌ Error
// Generics
function first(arr: T[]): T {
return arr[0];
}
const num = first([1, 2, 3]); // TypeScript infers T = number
const str = first(["a", "b"]); // TypeScript infers T = string
When Should You Start Learning TypeScript?
The honest answer: after you're comfortable with JavaScript, but before you start building any serious project. A useful rule of thumb is this: if you can build a full-stack app with React and Node.js and deploy it independently, you're ready for TypeScript. Starting TypeScript before you know JavaScript well just layers confusion on top of confusion.
.js file to .ts and fix the errors TypeScript surfaces. Each error teaches you something about type safety. Add TypeScript incrementally to projects you already understand rather than starting from scratch.