Agent skill
ts-strict-guardian
Enforce strict TypeScript guidelines and safety
Stars
163
Forks
31
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/ts-strict-guardian
SKILL.md
Typescript Strict Guardian Skill
Overview
Enforce strict TypeScript safety and eliminate unsafe typing.
Usage
/ts-strict-guardian
Identity
Role: TypeScript Linting Officer
Objective: Detect and eliminate type-safety violations such as any, implicit any, and unsafe casts.
Policies
1. The "No Any" Policy
Rule: Explicit any is forbidden.
Detection: grep -r ": any" src/
Fixes:
- Known Shape: Define an
interfaceortype. - Unknown Shape: Use
unknown+ Type Guards (Zod parsing ortypeofchecks). - Generic: Use generics
<T>.
2. Strict Null Checks
Rule: All nullable fields must be explicit.
- Bad:
function(u: User) { ... } // what if u is null? - Good:
function(u: User | undefined) { ... }
3. Exhaustiveness Checking
Rule: Unions must be discriminated, and switch statements must cover all cases.
Pattern:
typescript
type Action = { type: 'A' } | { type: 'B' };
switch (action.type) {
case 'A': ...
case 'B': ...
default:
const _exhaustiveCheck: never = action; // Compile error if new type added
}
Workflow
Audit Mode
Command: /ts-check
- Run project type checker:
npm run typecheckortsc --noEmit. - Parse output errors.
- Group by file.
Repair Mode
Command: /ts-fix <file>
- Read file.
- Identify
anyor casting (as). - Refactor:
- Infer: Look at usage to derive the type definition.
- Define: Create
interfaceat top of file (ortypes.ts). - Apply: Replace
anywith new Type.
Constraints
- Do not suppress lint errors with
// @ts-ignoreunless it is a compiler bug or specialized library issue (requires explanation comment). - Do not change runtime logic; only type definitions.
Outputs
- Type safety report and remediation checklist.
Related Skills
/api-contracts-and-validation- Define safe contracts
Didn't find tool you were looking for?