TypeScript Strictness Review
By p r i y a · Published · Updated
Tightens a TypeScript codebase by turning on strict flags, removing any, narrowing safely, modelling states as unions, and making async code fail loudly.
Prompt template
## TypeScript Strictness Review Make this TypeScript safer without rewriting it. - The code: [textarea: Paste the files or describe the module] - Current tsconfig: [textarea: Paste compilerOptions] - Runtime: [dropdown: Node, Browser, Both, Edge] - Areas: [multi: Strict flags, Removing any, Narrowing, Discriminated unions, Async safety, Null handling, Type exports] - Migration style: [dropdown: All at once, File by file, Only new code] First compare the tsconfig with the full strict family plus noUncheckedIndexedAccess and exactOptionalPropertyTypes, and say which flags to turn on and in what order so the error count stays manageable. Next, find each any and unknown cast: replace it with a real type, a generic, or unknown plus a narrowing check, and explain what the old any was hiding. Model states that carry different data (loading, success, failure) as a discriminated union with an exhaustive switch that ends in a never check. For async, look for promises that are never awaited, async functions inside forEach, and catch blocks that turn errors into undefined. Give the findings in the order you would fix them, each with a before and after snippet, and finish with a staged plan for enabling strictness at the chosen migration style.