You are viewing a free preview of this lesson.
Subscribe to unlock all 12 lessons in this course and every other course on LearningBro.
TypeScript is a statically typed superset of JavaScript developed and maintained by Microsoft. It adds optional type annotations, interfaces, generics, and other powerful features to JavaScript whilst compiling down to plain JavaScript that runs in any browser or Node.js environment. Since its first public release in 2012, TypeScript has grown to become one of the most popular languages in the world, consistently ranking in the top ten of developer surveys.
--strict flagTypeScript's type system catches entire categories of bugs before your code ever runs:
function greet(name: string): string {
return `Hello, ${name}!`;
}
// This would be caught at compile time:
// greet(42); // Error: Argument of type 'number' is not assignable to parameter of type 'string'
Without types, this mistake would silently pass in JavaScript and only surface at runtime — possibly in production.
Modern editors like VS Code use TypeScript's type information to provide:
Types serve as living documentation that never goes stale:
interface User {
id: number;
name: string;
email: string;
role: 'admin' | 'editor' | 'viewer';
}
Anyone reading this interface immediately understands the shape of a User without hunting through implementation code.
You do not need to rewrite your entire JavaScript project. TypeScript allows gradual adoption:
.js files to .ts one at a time// @ts-check in JavaScript files for lightweight checkingstrict: false and tighten over timeTypeScript is a compiled language. The TypeScript compiler (tsc) reads .ts files and emits plain .js files:
your-code.ts → tsc → your-code.js
The types are erased during compilation — they exist only at development time and have zero runtime overhead.
// Install globally
// npm install -g typescript
// Or as a project dependency (recommended)
// npm install --save-dev typescript
// npx tsc --init
// This creates a tsconfig.json with sensible defaults
The official TypeScript Playground lets you experiment with TypeScript directly in the browser. It is an excellent tool for:
| Feature | TypeScript | JavaScript |
|---|---|---|
| Type checking | Static (compile-time) | Dynamic (runtime) |
| Interfaces | Yes | No |
| Generics | Yes | No |
| Enums | Yes | No (only via workarounds) |
| IDE support | Excellent | Good |
| Learning curve | Moderate | Low |
| Adoption | Growing rapidly | Universal |
TypeScript is not a replacement for JavaScript — it is JavaScript with guardrails. Every valid JavaScript programme is also valid TypeScript, which makes migration straightforward.