Rebasely Beta: data may be purged

justintypescript-ultra-strict Public

Text · 27 lines · 705 B · at b0c0c21

import { tag, type Tagged, type Result } from "@tsus/runtime";type Light = Tagged<"Red", {}> | Tagged<"Amber", {}> | Tagged<"Green", {}>;// Forgot Amber: a compile-time error, not a runtime TSUS100.const next = (light: Light): Light =>  match (light) {    Red => tag("Green", {}),    Green => tag("Amber", {}),  };// Forgot Err.const report = (r: Result<number, string>): string =>  match (r) {    Ok(n) => `got ${n}`,  };type Method = "GET" | "POST" | "DELETE";// Literal patterns over a finite union must cover it, or add a _ arm.const verb = (m: Method): string =>  match (m) {    "GET" => "read",    "POST" => "write",  };console.log(next(tag("Red", {})).tag, report, verb);