From 9b3b16f779379c357fb1edff034c817edc090e55 Mon Sep 17 00:00:00 2001 From: Affaan Mustafa Date: Fri, 20 Mar 2026 06:18:49 -0700 Subject: [PATCH] feat(skills): add typescript-patterns skill --- skills/typescript-patterns/SKILL.md | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 skills/typescript-patterns/SKILL.md diff --git a/skills/typescript-patterns/SKILL.md b/skills/typescript-patterns/SKILL.md new file mode 100644 index 000000000..7befccaeb --- /dev/null +++ b/skills/typescript-patterns/SKILL.md @@ -0,0 +1,40 @@ +--- +name: typescript-patterns +description: TypeScript best practices, type safety, generics, async patterns, and project configuration for Claude Code and Codex. +--- + +# TypeScript Patterns + +## When to Use +- Working with TypeScript projects +- Adding type safety to JavaScript code +- Configuring tsconfig.json +- Using generics, utility types, or advanced type features + +## How It Works +1. Apply strict TypeScript configuration +2. Use proper type annotations and inference +3. Leverage generics for reusable components +4. Handle async/await with proper error types + +## Key Patterns + +### Strict Configuration +Always enable strict mode in tsconfig.json: strict, noUncheckedIndexedAccess, exactOptionalPropertyTypes. + +### Type-Safe Error Handling +Use discriminated unions for error types instead of throwing. Return Result types for fallible operations. + +### Generic Constraints +Constrain generics with extends to ensure type safety while maintaining flexibility. + +### Async Patterns +Use async/await with typed catch blocks. Prefer Promise.allSettled over Promise.all for parallel operations that can partially fail. + +### Utility Types +Use Pick, Omit, Partial, Required, Record for type transformations instead of manual type definitions. + +## Examples +- Use zod for runtime validation that generates TypeScript types +- Prefer const assertions for literal types +- Use satisfies operator for type checking without widening