cd ../skills
TypeScript Strict Patterns
Write type-safe TypeScript with strict mode enabled: no any, proper type guards, readonly patterns, and discriminated unions.
# TypeScript Strict Patterns
## When to Use
Apply in every TypeScript file across any project.
## Rules
1. **No `any` type** — use `unknown` with type guards, or proper interfaces.
2. **Use `interface`** for object shapes, `type` for unions and intersections.
3. **Mark arrays and properties `readonly`** when they shouldn't be mutated.
4. **Use discriminated unions** for state machines and variant types.
5. **Prefer named exports** — easier to refactor and tree-shake.
## Code Examples
```typescript
// Good — discriminated union
type Result<T> =
| { readonly success: true; readonly data: T }
| { readonly success: false; readonly error: string };
// Good — type guard
function isString(value: unknown): value is string {
return typeof value === 'string';
}
// Good — readonly arrays
interface Config {
readonly tags: readonly string[];
readonly allowedOrigins: readonly string[];
}
```
## Anti-Patterns
- Using `any` to "fix" type errors
- Not using strict mode in tsconfig
- Type assertions (`as`) without validation
- Mutable arrays in public APIs
## Checklist
- [ ] No `any` in codebase
- [ ] Strict mode enabled in tsconfig
- [ ] Readonly where appropriate
- [ ] Type guards for unknown dataHow to use this skill
- Click "Copy" to copy the skill content.
- Create a folder at
.github/skills/typescript-strict-patterns/in your repository. - Paste the content into
SKILL.mdinside the folder. - Reference the skill name in your AI agent's instructions or copilot config.