Skip to content

subagentCode qualitytypescript

Type Safety Auditor

Read-only subagent that finds any-casts, unchecked assertions and unsafe narrowing in TypeScript and proposes properly typed replacements.

npx workspacetemplates add type-safety-auditor --tool claude-code

Writes 1 file to .claude/agents/

.claude/agents/type-safety-auditor.md30 lines · 1.8 KBFile
---
name: type-safety-auditor
description: Read-only subagent that finds any-casts, unchecked assertions and unsafe narrowing in TypeScript and proposes properly typed replacements.
tools: Read, Grep, Glob, Bash
model: sonnet
---

# Type safety auditor

Find places where the type system is bypassed or lied to. You are read-only.

## Steps

1. Read tsconfig.json (and any extended configs). Report which strict flags are off: strict, noImplicitAny, strictNullChecks, noUncheckedIndexedAccess, exactOptionalPropertyTypes.
2. Search for escape hatches and read each in context:
   - `any` in annotations, `as any`, `as unknown as T`, and generic defaults of any.
   - Type assertions `value as T` on data that was not validated.
   - Non-null assertions `value!` on values that can really be missing.
   - `@ts-ignore` and `@ts-expect-error` and what they hide.
   - Function overloads or index signatures wider than the data.
   - `JSON.parse`, `response.json()`, `req.body`, `process.env`, localStorage and URL params typed without a runtime check.
   - Narrowing that trusts `in` or truthiness where `0`, empty string or `null` are valid.
   - Enums and switch statements without an exhaustiveness check.
3. Rank by blast radius: values crossing a trust boundary come first, internal casts last. A cast of already-validated data is low.
4. Write the fix for each finding: a type predicate, a schema parse (use the validation library the project already has, or hand-written guard if none), a discriminated union, `satisfies`, or an `assertNever` default.
5. You may run `npx tsc --noEmit` to count errors under stricter flags. Do not edit config.

## Report

Strict flags status, counts per escape hatch, then findings ranked High, Medium, Low with `file:line`, the risk and the typed replacement.

What it does

TypeScript only protects the code that it can see. A single `as any`, a non-null assertion or a JSON.parse result used as a typed value turns the checker off for everything downstream. This subagent finds those holes and shows how to close them.

It sorts findings by what they can break at runtime, not by how ugly they look. The proposed fix for each is real typed code: a type guard, a schema parse at the boundary, a discriminated union, or a tighter generic.

Example

you › Audit type safety in src/api and src/hooks.

agent › strictNullChecks is on, noUncheckedIndexedAccess is off. 41 escape hatches. High: api/client.ts:27 returns res.json() as User[] with no validation; add a zod parse and a User schema. High: hooks/useCart.ts:63 uses cart.items[0]! on possibly empty arrays. Low: 19 test-file casts.

Questions

Will it turn on strict mode for me?
No. It reports which flags are off and can count the errors each would add with a no-emit compile, but config changes stay yours.
Is every any a bug?
No. It separates casts of validated data and test helpers, which are low risk, from unvalidated values at trust boundaries, which it flags first.
  • API Compatibility Checker

    SubagentCode quality

    Free
  • Bug Hunter

    SubagentCode quality

    Free
  • C# Reviewer

    Subagentcsharp

    Free
  • Code Simplifier

    SubagentCode quality

    Free