Lesson 6 of 56 · Typescript
Type Aliases & Interfaces
Duration: 20 minutes
Type Aliases (type)
type Point = { x: number; y: number };
let p: Point = { x: 1, y: 2 };
Aliasing works for any type, including unions, intersections, and primitive literals.
Interfaces
interface Person {
name: string;
age?: number; // optional property
}
const alice: Person = { name: "Alice" };
Extending Interfaces
interface Employee extends Person {
employeeId: string;
}
const bob: Employee = { name: "Bob", employeeId: "E123" };
Declaration merging
If you declare the same interface twice, they merge:
interface Window { myProp: string; }
interface Window { another: number; }
// Window now has both properties