Union Types
type Direction = "left" | "right" | "up" | "down";
function move(direction: Direction) {
console.log(direction);
}
move("left");
type Size = 8 | 16 | 32;
const size: Size = 8;
const size1: Size = 7;
Intersection Types
type Student = {
name: string;
score: number;
};
type Worker = {
empolyeeId: number;
work: () => void;
};
function interWork(person: Student & Worker) {
console.log(
person.name,
person.empolyeeId,
person.empolyeeId,
person.work()
);
}
interWork({
name: "bae",
score: 100,
empolyeeId: 1,
work: () => {},
});