Introduction

Why TypeScript?

What is TypeScript?

TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale.

Key Point: TypeScript is JavaScript with syntax for types. It compiles to plain JavaScript and runs anywhere JavaScript runs.

The Problem with JavaScript

Runtime Errors
.js
// This looks fine ...

function greet(user) {
return 'Hello, ' + user.toUpperCase();
}

console.log(greet(42)); // ❌ Runtime error: user.toUpperCase is not a function

💥 Problem: JavaScript doesn"t know what type user is — so you might accidentally pass a number, and it crashes at runtime.

Poor Developer Experience
  • Limited autocomplete and IntelliSense
  • Difficult refactoring across large codebases
  • No compile-time error checking
  • Documentation often becomes outdated

How TypeScript Solves These Problems

Type Safety

Catch errors at compile time, not runtime. Prevent null/undefined errors and type mismatches.

Better Tooling

Enhanced autocomplete, refactoring, and navigation. Your IDE becomes much more powerful.

Self-Documenting

Types serve as documentation that never goes out of date. Code becomes more readable.

Team Collaboration

Clear contracts between different parts of your application. Easier onboarding for new team members.

Before & After: A Simple Example

JavaScript (Before)
Prone to runtime errors
.js
function greet(user) {
return "Hello, " + user.name.toUpperCase();
}

const user = { firstName: "Alice" };
console.log(greet(user)); // ❌ TypeError: Cannot read property 'toUpperCase' of
undefined

What happened?

  • JavaScript didn’t tell you anything at build time.
  • At runtime,  user.name is undefined → crash.

TypeScript (After)
Type-safe and self-documenting
.ts
type User = {
name: string;
};

function greet(user: User): string {
return "Hello, " + user.name.toUpperCase();
}

const user = { firstName: "Alice" };
console.log(greet(user)); // ❌ Error: Property 'name' is missing in type

TypeScript catches:

  • "firstName" is not "name". It tells you immediately before running your code.

Key Takeaways

TypeScript is JavaScript with types -you're not learning a completely new language
Gradual adoption is possible - you can migrate existing JavaScript projects incrementally
Better developer experience - catch errors early, better tooling, improved productivity
Industry standard - widely adopted by major companies and open source projects