Kill every redundant type assertion and non-null assertion in your TypeScript codebase
For each assertion.
- Delete it.
- Typecheck via
tsgo. - Keep the deletion if it typechecks; revert otherwise.
What survives is the set of assertions actually doing work — plus the small set preserved by rule.
A few cases where an assertion is kept even though tsgo would accept the deletion:
as const— never touched.as never— never touched; almost always an intentional type hack.x as Twhenxhas typeany(andT≠any) — removing it would letanysilently propagate.x as any as T— neither half is removed in a way that would change the value's effective type. Whenxalready has typeany, the inneras anyis removed and the outeras Tstays.- An assertion inside a function with an inferred return type, when removing it would change the function's inferred return type. Functions with an explicit return annotation are exempt.
{ ... } as Tinitializing an unannotated variable — on object literals the assertion drives contextual typing inside the braces: editor property suggestions, per-field checks.x!whenstrictNullChecksis off — usually scaffolding for an in-progress migration to strict null checks.
npx asserticide # uses ./tsconfig.json
npx asserticide path/to/tsconfig.json
npx asserticide path/to/dir # uses path/to/dir/tsconfig.jsonRequires Node ≥ 24. asserticide refuses to run if the project doesn't typecheck cleanly under tsgo. Commit your working tree first so you can review the diff afterwards.
Sample output:
---
total assertions found: 412
removed assertions: 287
reverted by typecheck: 118
preserved by rule: 7
files changed: 54
- src/api/client.ts
- src/components/Grid.tsx
- ...
The difference is scale.
The @typescript-eslint/no-unnecessary-type-assertion lint rule works at the expression level: it reports an assertion when removing it preserves the expression type or still satisfies the contextual type at that position.
asserticide works at project level: it tries deleting each type assertion, runs tsgo, and keeps the edit if the checked project still typechecks and no preservation rule applies.
So asserticide can remove assertions with real local type effects when those effects are unused projectwide.
