Agent skill
typecheck
TypeScript type-safety rules and guidance.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/typecheck
SKILL.md
Typecheck Skill
Use this skill when handling TypeScript type errors or type-safety decisions.
Core Rule: Never Use as any
CRITICAL: NEVER add as any type assertions to fix TypeScript errors. If you
cannot figure out a proper type-safe solution, tell the user that you can't
figure it out rather than using as any.
Rationale
Using as any:
- Disables type checking, removing TypeScript's safety guarantees
- Hides actual type problems that should be addressed properly
- Makes the codebase more error-prone and harder to maintain
- Is a code smell that indicates deeper type design issues
What to Do Instead
- Investigate the root cause: Understand why TypeScript can't infer the correct type
- Use proper type narrowing: Use type guards, conditional types, or better type constraints
- Fix the type definitions: Update interfaces, generics, or type utilities if needed
- Ask for help: If you truly cannot solve it type-safely, inform the user that you cannot figure out a proper solution
When Encountering Type Errors
-
✅ DO: Analyze the error message carefully to understand the type mismatch
-
✅ DO: Check if helper types or type utilities can resolve it
-
✅ DO: Consider if the API or type definitions need improvement
-
✅ DO: Tell the user if you cannot find a type-safe solution
-
❌ DON'T: Add
as anyto silence the error -
❌ DON'T: Use
as unknown as Tas a workaround (same problem asas any) -
❌ DON'T: Use
@ts-ignoreor@ts-expect-errorto suppress type errors
Examples of What NOT to Do
// ❌ WRONG - Never do this
const rows = yield* db
.select()
.from(pgTable as any)
.where(eq(pgTable.id, id));
// ❌ WRONG - This is also bad
const value = someValue as unknown as ExpectedType;
When You Cannot Solve It Type-Safely
If after careful analysis you cannot find a type-safe solution, you should:
- Explain what the type error is
- Describe what you tried
- State clearly that you cannot figure out a proper type-safe solution
- Suggest potential approaches (better type definitions, helper utilities, etc.)
Example response:
"I'm encountering a TypeScript error where
pgTablefrommodels[modelName]cannot be properly narrowed for use in Drizzle's.from()method. The complex generic types fromInferAggregateModelsare preventing proper type inference. I've tried [X, Y, Z approaches] but cannot find a type-safe solution. This likely requires improving the type definitions for the table mapping or using a different pattern for accessing tables. I cannot figure out a proper type-safe fix for this."
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?