Get Started
Back to Skill Shed
Coding

Strict TypeScript Guardian

Prompte27 February 2026IntermediateClaude Code, Codex, Cursor, Windsurf, Aider
typescriptstrict-modetype-safetybest-practices

What This Skill Does

Instructs your AI coding assistant to enforce strict TypeScript conventions across every file it touches. No any types, explicit return types on exports, readonly by default, and discriminated unions instead of type assertions.

When to Use It

Activate this skill on any TypeScript project where type safety matters. Especially useful for:

  • Greenfield projects where you want strict conventions from day one
  • Codebases migrating from JavaScript where any tends to creep in
  • Teams where multiple developers (or AI agents) contribute code

What Changes

Your AI assistant will:

  • Replace any with unknown + type guards
  • Add explicit return types to all exported functions
  • Use readonly on arrays and object properties unless mutation is required
  • Prefer discriminated unions over type assertions
  • Never use non-null assertion (!) without justification

Skill File

strict-typescript-guardian.skill.md
---
name: strict-typescript-guardian
description: >
  Enforce strict TypeScript practices in all generated code. Use this skill
  whenever writing or modifying TypeScript files. Ensures no `any` types,
  explicit return types, readonly by default, and discriminated unions.
---

# Strict TypeScript Guardian

You are a TypeScript expert who enforces strict type safety at all times.

## Core Rules

1. **Never use `any`** - Use `unknown` with type guards, or define proper interfaces
2. **Explicit return types** - All exported functions must declare their return type
3. **Readonly by default** - Use `readonly` on arrays and object properties unless mutation is required
4. **Discriminated unions** - Prefer tagged unions over type assertions or `as` casts
5. **Strict null checks** - Handle null/undefined explicitly, never use non-null assertion (!)
6. **No implicit any** - All function parameters must be typed

## Type Guard Pattern

When narrowing `unknown`, always use type guards:

```typescript
function isUser(value: unknown): value is User {
  return (
    typeof value === "object" &&
    value !== null &&
    "id" in value &&
    "name" in value
  )
}
```

## Interface Over Type Alias

Prefer `interface` for object shapes (extendable, better error messages).
Use `type` only for unions, intersections, or mapped types.

## Error Handling

Always type catch blocks:

```typescript
try {
  await fetchData()
} catch (error: unknown) {
  if (error instanceof ApiError) {
    handleApiError(error)
  }
  throw error
}
```

Install

Claude Code

Save to your project's .claude/skills/ directory. Claude Code picks it up automatically.

Save to:
.claude/skills/strict-typescript-guardian.skill.md
Or use the command line:
mkdir -p .claude/skills/ && curl -o .claude/skills/strict-typescript-guardian.skill.md https://prompte.app/skill-shed/strict-typescript-guardian/raw

Explore more skills

Browse the full library of curated skills for your AI coding CLI.