</>
Skip to content
TypeScript lessons (2/31)

TypeScript — Introduction

What is TypeScript?

TypeScript is JavaScript with types. Created by Microsoft in 2012, it adds static type checking to JavaScript while compiling down to plain JavaScript. Every valid JavaScript file is also a valid TypeScript file.

// TypeScript
function greet(name: string): string {
    return `Hello, ${name}!`;
}

// Compiles to JavaScript
function greet(name) {
    return `Hello, ${name}!`;
}

TypeScript adds types at development time. The compiled JavaScript has no type information — it runs anywhere JavaScript runs.

Why TypeScript exists

JavaScript is flexible but error-prone. TypeScript catches errors before your code runs:

function add(a: number, b: number): number {
    return a + b;
}

add("hello", 5);  // Error: argument of type 'string' is not assignable

In plain JavaScript, this silently produces "hello5". TypeScript catches it immediately.

TypeScript's benefits

  • Catch bugs at compile time — not in production
  • Better IDE support — autocomplete, refactoring, inline documentation
  • Safer refactoring — change a function signature and the compiler shows every call that needs updating
  • Self-documenting — types serve as documentation for other developers
  • Gradual adoption — add types file by file to existing JavaScript projects

What TypeScript adds to JavaScript

FeatureJavaScriptTypeScript
Type annotationsNoYes
InterfacesNoYes
GenericsNoYes
EnumsNoYes
Access modifiersNoYes (public/private/protected)
Compile-time checkingNoYes

TypeScript is a superset

JavaScript ⊂ TypeScript

Every valid JavaScript file is valid TypeScript. You don't need to rewrite existing code — add .ts extension and start adding types gradually.

How TypeScript works

TypeScript (.ts) → TypeScript Compiler (tsc) → JavaScript (.js)

The compiler checks types and strips them, producing plain JavaScript. This means TypeScript runs everywhere JavaScript runs — browsers, Node.js, Deno.

A taste of TypeScript

// Type annotations
let name: string = "Ada";
let age: number = 36;
let active: boolean = true;

// Function types
function multiply(a: number, b: number): number {
    return a * b;
}

// Interface
interface Person {
    name: string;
    age: number;
    email?: string;  // optional
}

// Using the interface
const ada: Person = {
    name: "Ada",
    age: 36
};

// Array types
const scores: number[] = [95, 87, 92];
const names: Array<string> = ["Ada", "Grace"];

Who uses TypeScript?

  • Microsoft — created it; used in VS Code, Azure
  • Google — Angular is written in TypeScript
  • Facebook — adopted for React projects
  • Netflix, Airbnb, Stripe — large-scale TypeScript adoption

TypeScript is the fastest-growing language in the Stack Overflow survey.

TypeScript vs JavaScript

TypeScript isn't a replacement for JavaScript — it's a development tool:

  • Write TypeScript for better developer experience
  • Compile to JavaScript for production
  • TypeScript = JavaScript + safety

What you'll learn

  1. Type annotations and basic types
  2. Interfaces and type aliases
  3. Generics for reusable code
  4. Classes with access modifiers
  5. Modules and imports
  6. Configuration with tsconfig.json

TypeScript has a gentle learning curve — you can add types gradually, one file at a time.

Next: setting up TypeScript →

Related Topics

Frequently Asked Questions about Introduction

What is Introduction in TypeScript?

Introduction is a fundamental concept in TypeScript. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Introduction?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Introduction.

Why is Introduction important in TypeScript?

Introduction is essential for TypeScript development. Understanding this concept will help you write better code and solve real-world problems more effectively.