ofershap/typescript-best-practices/typescript-best-practices
Claude Code and agent skill by ofershap/typescript-best-practices
- community
Checking that the SKILL.md file is still in the repository.
Modern TypeScript patterns your AI agent should use. Strict mode, discriminated unions, satisfies operator, const assertions, and type-safe patterns for TypeScript 5.x.
Install
npx vskill@latest install ofershap/typescript-best-practices/typescript-best-practicesSKILL.md
When to use
Use this skill when working with TypeScript code. AI agents frequently generate outdated patterns - using any instead of unknown, type assertions instead of satisfies, optional fields instead of discriminated unions, and missing strict mode options. This skill enforces modern TypeScript 5.x patterns.
Critical Rules
1. Enable Strict Mode with All Checks
Wrong (agents do this):
Correct:
Why: Strict mode catches entire categories of bugs. noUncheckedIndexedAccess prevents unsafe array/object access. Agents often skip these for "convenience."
2. Use satisfies Instead of Type Assertions
Wrong (agents do this):
Correct:
Why: satisfies validates the type without widening it. as silences the compiler and can hide bugs. Use satisfies for validation, as only when you genuinely know more than the compiler.
3. Use Discriminated Unions Over Optional Fields
Wrong (agents do this):
Correct:
Why: Optional fields allow impossible states (data AND error both present). Discriminated unions make each state explicit and exhaustively checkable.
4. Use const Assertions for Literal Types
Wrong (agents do this):
Correct:
Why: Without as const, TypeScript widens literal types to string. With it, you get exact literal types and readonly properties.
5. Use unknown Instead of any
Wrong (agents do this):
Correct:
Why: any disables all type checking. unknown forces you to narrow the type before using it, catching bugs at compile time.
6. Use Template Literal Types for String Patterns
Wrong (agents do this):
Correct:
Why: Template literal types create precise string patterns from unions. The compiler catches typos and invalid combinations at build time.
7. Use NoInfer to Prevent Unwanted Inference
Wrong (agents do this):
Correct:
Why: NoInfer<T> (TypeScript 5.4+) prevents a parameter from influencing type inference, ensuring stricter checks.
8. Use Branded Types for Type-Safe IDs
Wrong (agents do this):
Correct:
Why: Branded types prevent accidentally passing one ID type where another is expected. The brand exists only at compile time - zero runtime cost.
9. Use Exhaustive Switch with never
Wrong (agents do this):
Correct:
Why: The never check ensures every union member is handled. When a new status is added, the compiler flags the missing case.
10. Use Type Predicates Over Type Assertions
Wrong (agents do this):
Correct:
Why: Type predicates (item is User) narrow types safely with runtime checks. Type assertions (as User) bypass the compiler and can hide bugs.
11. Use import type for Type-Only Imports
Wrong (agents do this):
Correct:
Why: import type is erased at compile time, reducing bundle size. It also makes the intent clear - this import is for types only.
12. Use Record Over Index Signatures
Wrong (agents do this):
Correct:
Why: Record<K, V> is more readable and composable than index signatures. When possible, use a union for keys to get exhaustive checking.
13. Use using for Resource Management
Wrong (agents do this):
Correct:
Why: The using keyword (TypeScript 5.2+) provides deterministic resource cleanup via the Disposable protocol, similar to Python's with or C#'s using.
Patterns
- Enable
strict: trueandnoUncheckedIndexedAccess: truein every project - Use
satisfiesfor type validation without widening - Use discriminated unions with a
typeorkindfield for state modeling - Use
as constfor configuration objects and route maps - Use branded types for domain-specific IDs
- Use
import typefor all type-only imports - Use exhaustive
switchwithneverdefault for union handling
Anti-Patterns
- NEVER use
any- useunknownand narrow with type guards - NEVER use
asfor type assertions unless you genuinely know more than the compiler - NEVER use optional fields to model mutually exclusive states - use discriminated unions
- NEVER use
// @ts-ignoreor// @ts-expect-errorwithout a comment explaining why - NEVER use
enum- useas constobjects or union types instead - NEVER use
Functiontype - use specific function signatures - NEVER disable strict mode for convenience
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/typescript-best-practices/SKILL.md
Popularity
- Repository stars
- 1
- 7-day trend score
- 3
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 16 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/ofershap/typescript-best-practices/typescript-best-practices)