Lesson 1 of 3

Introduction to TypeScript

Discover what TypeScript is, why it's become essential for modern development, and how to set up your first TypeScript project.

20 minutes

Introduction to TypeScript

TypeScript is a strongly typed superset of JavaScript that compiles to plain JavaScript.

Why TypeScript?

  • Type Safety: Catch errors at compile time, not runtime
  • Better IDE Support: Enhanced autocomplete, refactoring, and navigation
  • Scalability: Makes large codebases easier to maintain
  • Modern Features: Access to latest JavaScript features with backward compatibility

Setting Up Your First Project

Get started with TypeScript in just a few commands:

npm init -y
npm install typescript --save-dev
npx tsc --init

Project Structure

  • tsconfig.json: TypeScript compiler configuration
  • src/: Your TypeScript source files
  • dist/: Compiled JavaScript output

Key Concepts Preview

  • Types add safety to your variables and functions
  • Interfaces define contracts for objects
  • Generics provide reusable type-safe components
  • The compiler catches errors before runtime

Code Example

// Your first TypeScript file

// Basic type annotations
let message: string = "Hello, TypeScript!";
let count: number = 42;
let isActive: boolean = true;

// Function with typed parameters and return type
function greet(name: string): string {
  return `Welcome to TypeScript, ${name}!`;
}

console.log(greet("Developer"));
// Output: Welcome to TypeScript, Developer!