Agent skill
typescript-strict
Use when writing TypeScript with strict mode - covers type definitions, generics, and declaration files
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/typescript-strict-mcclowes-lea-2
SKILL.md
TypeScript Strict Mode Best Practices
Quick Start
// Enable strict in tsconfig.json
{
"compilerOptions": {
"strict": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true
}
}
Core Principles
- Strict null checks: Handle
undefinedandnullexplicitly - No implicit any: Always declare types, avoid
any - Readonly by default: Use
readonlyfor immutable data - Discriminated unions: Use type guards with tagged unions
Type Definition Patterns
AST Node Types
// Discriminated union for AST nodes
type Expr =
| { type: "NumberLiteral"; value: number }
| { type: "BinaryExpr"; op: string; left: Expr; right: Expr }
| { type: "Identifier"; name: string };
// Type guard
function isNumberLiteral(expr: Expr): expr is Extract<Expr, { type: "NumberLiteral" }> {
return expr.type === "NumberLiteral";
}
Generic Types
// Constrained generics
function map<T, U>(arr: readonly T[], fn: (item: T, index: number) => U): U[] {
return arr.map(fn);
}
// Conditional types
type Unwrap<T> = T extends Promise<infer U> ? U : T;
Declaration Files
// module.d.ts
declare module "lea-lang" {
export function run(code: string): unknown;
export function parse(code: string): Program;
}
Common Patterns
- Use
unknownoveranyfor safer type narrowing - Prefer
interfacefor extendable types,typefor unions - Use
as constfor literal types - Leverage
satisfiesfor type checking without widening
Reference Files
- references/generics.md - Advanced generic patterns
- references/type-guards.md - Type narrowing techniques
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?