type Result = | { ok: true; value: T } | { ok: false; error: string }; export enum Status { Idle = 'idle', Busy = 'busy', Failed = 'failed' } export interface FileSpec { readonly path: string; bytes: number; tags?: string[]; } /** Generic angle brackets are what a JavaScript-only tokeniser trips over. */ export function unwrap(r: Result, fallback: T): T { return r.ok ? r.value : fallback; } export const SIZES = { small: 1024, large: 1048576 } as const; export function describe(spec: FileSpec): string { const { path, bytes } = spec; const kind: Status = bytes > SIZES.large ? Status.Busy : Status.Idle; return `${path} is ${bytes} bytes (${kind})`; } const check = { path: 'a.txt', bytes: 12 } satisfies FileSpec; export default check;