---
name: typescript-strictness-review
description: "Tightens a TypeScript codebase by turning on strict flags, removing any, narrowing safely, modelling states as unions, and making async code fail loudly. Use when a TypeScript codebase has loose compiler settings, scattered any types, or unsafe async code and needs a path to strict mode. Do not use for converting a JavaScript project to TypeScript from scratch. Related topics: coding, technical."
---

# TypeScript Strictness Review

Tightens a TypeScript codebase by turning on strict flags, removing any, narrowing safely, modelling states as unions, and making async code fail loudly.

## When to use

Use this skill when a TypeScript codebase has loose compiler settings, scattered any types, or unsafe async code and needs a path to strict mode. Do not use it for converting a JavaScript project to TypeScript from scratch.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Compare the tsconfig with the strict family and list which flags to enable, ordered by how few errors each is likely to add.
3. Find every any, non-null assertion, and unchecked cast, and replace each with a proper type or a narrowing check.
4. Rewrite state-like data as a discriminated union with an exhaustive switch that ends in a never check.
5. Scan async code for unawaited promises, async callbacks in forEach, and catch blocks that hide errors, and fix each.
6. Lay out a staged plan for turning on strictness at the chosen migration style.

## Inputs

- **The code** (longer free text)
- **Current tsconfig** (longer free text)
- **Runtime** (choose one: Node, Browser, Both, Edge)
- **Areas** (choose any: Strict flags, Removing any, Narrowing, Discriminated unions, Async safety, Null handling, Type exports)
- **Migration style** (choose one: All at once, File by file, Only new code)

## Output

Findings in fix order with before and after snippets, followed by a staged rollout plan for the compiler flags.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### TypeScript Strictness Review

Make this TypeScript safer without rewriting it.

- The code: {{The code}}
- Current tsconfig: {{Current tsconfig}}
- Runtime: {{Runtime}}
- Areas: {{Areas}}
- Migration style: {{Migration style}}

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.

## Pitfalls

- Enabling every strict flag in one commit, which floods the team with hundreds of errors and stalls the effort.
- Swapping any for unknown without adding the narrowing check, so the code only moves the problem.
- Using non-null assertions to silence the compiler, which trades a compile error for a runtime crash.
