Rebasely Beta: data may be purged

justintypescript-ultra-strict Public

JavaScript · 49 lines · 2.2 KiB · at 9c48a39

// Stable diagnostic codes owned by the compiler (preprocessor + semantic// pass). The strictness rules (TSUS001-005) live next to their checks in// check.js. TSUS2xx wrap a TypeScript diagnostic and always carry its numeric// code as `tsCode`.export const CODES = {  TSUS000: {    message: "syntax error",    hint: "The file does not parse as TypeScript after macro expansion.",  },  TSUS006: {    message: "malformed match expression",    hint: "Arms look like: Variant(binding) => expression, \"literal\" => expression, or _ => expression, separated by commas.",  },  TSUS200: {    message: "type error",    hint: "The original TypeScript diagnostic is in tsCode and the message.",  },  TSUS201: {    message: "non-exhaustive match",    hint: "Add an arm for every missing variant, or a _ arm to cover the rest.",  },  TSUS202: {    message: "match arm does not fit the subject",    hint: "Each pattern must be a variant tag (or literal value) the subject's type can actually hold.",  },  TSUS203: {    message: "match subject is not matchable",    hint: "Variant patterns need a tagged union (a `tag` field); literal patterns need a string, number, bigint, or boolean subject.",  },  TSUS300: {    message: "? used outside a function that returns Result or Option",    hint: "Declare the enclosing function's return type as Result<T, E>, Option<T>, or Promise<...> of one; ? cannot be used at top level or inside match arms, which are closures.",  },  TSUS301: {    message: "? applied to a value that is not a Result or Option",    hint: "Only Result and Option values can be propagated with ?. In async code, await first: `const x = await load()?;`.",  },  TSUS302: {    message: "? propagates a value the function cannot return",    hint: "An Err must match the function's error type, and None can only propagate out of a function returning Option. Convert first (mapErr, okOr).",  },  TSUS303: {    message: "? in a position that may not run",    hint: "? is lowered to an early return before the statement, so it cannot sit in a ?: branch, the right side of && || ??, or a loop condition. Move it into its own statement.",  },};export const describe = (code) => CODES[code] ?? { message: code, hint: "" };