TypeScript Literal Types
let direction: "up" | "down" | "left" | "right";
direction = "up";
// direction = "north"; // Error: not assignable
type HttpMethod = "GET" | "POST" | "PUT" | "DELETE";
function request(url: string, method: HttpMethod): void {
console.log(`${method} ${url}`);
}
request("/users", "GET");