Skip to main content
Agent skill

Code Review Type Safety

Type-safety code review lens for catching type errors, schema mismatches, and unsafe type coercions.

Get started

Get the complete skill folder, including its scripts and reference files.

When to use this skill

Use Code Review Type Safety when an AI agent needs a reusable SKILL.md workflow for this job: Type-safety code review lens for catching type errors, schema mismatches, and unsafe type coercions.

When not to use it

Skip Code Review Type Safety when the task is outside the analysis category, or when a more specific skill in this directory already covers the same workflow with clearer triggers.

How to install

Where will you use it?

Install scope
Claude Code folder setup
mkdir -p ~/.claude/skills/code-review-type-safety
# Save SKILL.md to ~/.claude/skills/code-review-type-safety/SKILL.md
  1. Claude Code personal install: place the skill and its bundled files at ~/.claude/skills/code-review-type-safety/SKILL.md. For a shared project, commit the folder at .claude/skills/code-review-type-safety/ instead.
  2. Current Claude Code detects SKILL.md changes in watched directories during the session. If you just created a top-level skills directory, run /reload-skills. Check that the skill is listed before testing its trigger.
  3. For Claude chat or Cowork in the Desktop app, manage uploaded skills in Customize > Skills; copying files into a local Claude Code folder is not a Desktop install. Other agents may use different install locations.

Full install guide for Claude, Cursor, and Codex →

Try a starter prompt

After installing the skill, paste this starter prompt into your agent to verify it triggers on a small task.

Starter prompt
Use the Code Review Type Safety skill for this task: Use Code Review Type Safety when this documented workflow matches the task. Confirm any required inputs or files before making changes.

What supports this recommendation?

66/100 provisional content score. This measures documentation, practical detail and source signals. It is not a measured task success rate or a security certification.

Documentation
70/100
Practical detail
68/100
Source evidence
53/100
Source signals
72/100
Model compatibility evidence
  • claudeuntested

    No model-specific signal or recorded compatibility test was found.

  • chatgptuntested

    No model-specific signal or recorded compatibility test was found.

  • geminiuntested

    No model-specific signal or recorded compatibility test was found.

  • copilotuntested

    No model-specific signal or recorded compatibility test was found.

  • llamauntested

    No model-specific signal or recorded compatibility test was found.

  • perplexityuntested

    No model-specific signal or recorded compatibility test was found.

  • mistraluntested

    No model-specific signal or recorded compatibility test was found.

  • grokuntested

    No model-specific signal or recorded compatibility test was found.

Inferred compatibility is based on content signals. Check the app, its available tools and setup requirements before running a skill.

What this skill does

# Code Review: Type Safety Lens

Specialized agent for type safety analysis during code review. Focuses on catching type errors, verifying type coverage, and ensuring proper type discipline.

## Scope Discipline

When PM explicitly dispatches this lens: - ✅ Review type-related concerns: type errors, type coverage, proper typing - ✅ Analyze type definitions, interfaces, type annotations - ✅ Check for type coercion issues and unsafe type usage - ✅ Verify generic constraints and type parameters

Do NOT broaden into: - ❌ Security vulnerabilities (use SECURITY lens) - ❌ Error-handling hygiene, timeout discipline, retry semantics (use ERROR_HANDLING lens) - ❌ Performance characteristics (use PERFORMANCE lens) - ❌ Architectural patterns (use ARCHITECTURE lens) - ❌ Code complexity/readability (use SIMPLICITY lens)

## Output Format

All findings must follow this structure:

```markdown ## Must Fix - [CRITICAL|HIGH] [path:line] Title - Description: What is wrong and why it matters - Suggestion: Specific fix with code example - Metadata: cross_lens_candidate=true/false, tradeoff_required=true/false

## Observations - [MEDIUM|LOW] [path:line] Title - Description: Informational finding - Metadata: cross_lens_candidate=true/false, tradeoff_required=true/false

## Summary [One paragraph overall assessment] ```

## Severity Scale

- **CRITICAL**: A type gap that reaches a real failure and the finding says how — a cast that lets unvalidated input through a boundary that then corrupts or leaks data, or a schema mismatch that breaks a contract another component depends on. - **HIGH**: A concrete, reachable failure on a realistic input that the type error permits — the finding names the input and the wrong result, e.g. a cast that lets `{}` through a boundary whose reader then throws on `.items.length`. Naming a typing defect is not evidence on its own. - **MEDIUM**: Type nits — missing annotations where one would help, `implicit any`, verbose or redundant type definitions, a cast that could be a guard without changing behaviour. - **LOW**: Cosmetic type style.

## Metadata Guidance Tags

When reporting findings, always include:

**cross_lens_candidate**: Indicates this finding might also be relevant to other lenses - `true` if this finding could trigger other lens checks (e.g., missing validation might be both type and security) - `false` if this is purely a type safety concern

**tradeoff_required**: Indicates if fixing this requires accepting a tradeoff - `true` if the fix involves complexity, performance, or API design tradeoffs - `false` if the fix is straightforward with no downside

## What to Review

1. **Type Coverage** - Are all public APIs properly typed? - Are critical internal functions typed? - Are implicit any usage justified? (an unjustified one is a MEDIUM nit, not a finding about harm)

2. **Type Correctness** - Do type annotations match actual usage? - Are type assertions (@ts-ignore, as) justified and minimal? - Are type guards properly implemented?

3. **Type Safety** - Are unsafe operations (unknown types, force casts) minimized? - Are runtime type validations used where needed? - Are discriminated unions properly typed?

4. **Generic Discipline** - Are generic constraints appropriate? - Are generics used where they add value? - Are type parameters properly bounded?

## Example Finding

```markdown ## Must Fix - [HIGH] [src/api.ts:42] Unvalidated response is cast to ApiResponse and read downstream - Description: `parseResponse` casts `JSON.parse(body)` to `ApiResponse` with no runtime check. A 200 whose body is `{}` — what the upstream returns when its cache is cold — reaches `render(user.data.items.length)` in `src/views/user.ts:18` and throws a TypeError that blanks the page. - Suggestion: Validate at the boundary: `function parseResponse(data: string): ApiResponse | undefined` behind a type guard on the fields the callers read. - Metadata: cross_lens_candidate=true, tradeoff_required=false ```

## Adversarial Input Discipline

Before returning any verdict, construct one concrete input of an unexpected type, shape, or nullability that exercises the primary code path modified in the diff, and state what the type system or runtime does with it. If you cannot construct such an input, your review is incomplete — say so in your summary with the code path you could not exercise, rather than reporting nothing.

## Integration Notes

This lens is part of the six-pass code review protocol. Findings are merged with other lenses via deterministic synthesis: - Dedupe by (path, line, title) - Precedence: SECURITY > ERROR_HANDLING > TYPE_SAFETY > PERFORMANCE > ARCHITECTURE > SIMPLICITY

Intended uses

  • Use Code Review Type Safety when this documented workflow matches the task.

Implementation notes

  • Review the source instructions and adapt inputs before running the workflow.

Try it, then tell us how it went

A copied prompt does not tell us whether the task worked. Report your result after checking the output. We collect your tool and outcome, never your files or prompt.