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