Skip to content

skillCode qualitytypescript

TypeScript Strict Migration

Moves a TypeScript project to strict mode one compiler flag at a time, fixing each wave of errors with real types instead of any casts or ts-ignore.

npx workspacetemplates add typescript-strict-migration --tool claude-code

Writes 1 file to .claude/skills/typescript-strict-migration/

.claude/skills/typescript-strict-migration/SKILL.md30 lines · 1.8 KBFile
---
name: typescript-strict-migration
description: Moves a TypeScript project to strict mode one compiler flag at a time, fixing each wave of errors with real types instead of any casts or ts-ignore.
---

# TypeScript strict migration

The aim is a green `tsc --noEmit` after every flag, with no new escape hatches.

## Steps

1. Read `tsconfig.json` (and any extended config). Run `npx tsc --noEmit` and record the baseline error count. Count existing `any`, `@ts-ignore` and `as unknown as` so you can show they did not grow.
2. Enable flags in this order, running `tsc` after each: `noImplicitAny`, `strictNullChecks`, `strictFunctionTypes`, `strictBindCallApply`, `strictPropertyInitialization`, `noImplicitThis`, `useUnknownInCatchVariables`, `alwaysStrict`. When all are on, replace them with `"strict": true`.
3. For each flag, group errors by file and fix the leaf modules first (utilities, types), then the code that uses them.
4. Fix with real types:
   - Missing annotations: write the type from how the value is used; derive it with `typeof` or `ReturnType` when possible.
   - Possibly null: narrow with a check or an early return. Use `?.` and `??` only when the fallback is correct.
   - Catch variables: narrow with `instanceof Error`.
   - Uninitialized properties: initialize in the constructor or mark optional; use `!` only with a comment naming the guarantee.
5. If a flag yields over 150 errors, split by directory and use a per-folder tsconfig that extends the base.
6. Run the tests and the linter before moving to the next flag.

## Rules

- Never add `any`, `@ts-ignore` or a blanket non-null `!` to clear an error.
- Do not change runtime behavior; if a fix needs a behavior change, report it.

## Report

Per flag: errors fixed, files touched, and the final counts of any and ignores compared with the start.

What it does

Switching on "strict" in one step gives you thousands of errors and a pull request nobody can review. This skill enables the flags one by one, in an order that keeps each batch small, and commits a clean build after every flag.

The fixes are honest ones: narrowing, proper types and handled null cases. Casting to any or silencing with a comment is treated as a failure, not a shortcut.

Example

you › Turn on strict for this project, one flag at a time.

agent › Baseline: 0 errors, strict off. noImplicitAny: 62 errors fixed in 14 files. strictNullChecks: 188 errors, split into 3 steps by folder; found 2 real bugs where `user.email` could be undefined in the mailer. Now `"strict": true`, tsc clean, tests pass. any count 9 to 4, no new ts-ignore.

Questions

Why not enable strict and fix everything together?
The diff becomes too big to review and a single bad fix hides among hundreds. Flag by flag keeps every step revertable.
What if a library has bad types?
The skill writes a small local declaration or wrapper with accurate types and notes it in the report, rather than casting at each call site.
  • API Deprecation Handling

    SkillCode quality

    Free
  • Code Duplication Removal

    SkillCode quality

    Free
  • Code Smell Detection

    SkillCode quality

    Free
  • Concurrency Bug Analysis

    SkillCode quality

    Free