<< All versions
❌ NEVER: use
✅ REQUIRED: Use
✅ REQUIRED: Use
✅ REQUIRED: Use
Skill v1.0.1
currentAutomated scan100/100joabgonzalez/ai-agents-skills/typescript
10 files
──Details
PublishedSeptember 26, 2026 at 02:47 AM
Content Hashsha256:017b4b1fc62a4349...
Git SHA996910df28e2
Bump Typepatch
──Files
Files (1 file, 6.4 KB)
SKILL.md6.4 KBactive
SKILL.md · 285 lines · 6.4 KB
version: "1.0.1" name: typescript description: "Strict typing and type-safe development. Trigger: When implementing TypeScript in .ts/.tsx files, adding types, or enforcing safety." license: "Apache 2.0" metadata: version: "1.1" type: language dependencies: typescript: ">=5.0.0 <6.0.0"
TypeScript
Strict typing with compile-time correctness. Avoid any, leverage generics/utility types.
When to Use
Use when:
- Writing or refactoring
.ts/.tsxfiles - Adding type definitions, interfaces, or type aliases
- Working with generics, utility types, or advanced type features
- Configuring
tsconfig.json - Resolving type errors or improving type inference
Don't use for:
- Runtime validation (form-validation)
- JS-only patterns (javascript skill)
- Framework typing (react, mui skills)
Critical Patterns
❌ NEVER: use any
typescript
// BAD: Disables type checkingfunction process(data: any) {return data.value;}// GOOD: unknown with type guardsfunction process(data: unknown) {if (typeof data === "object" && data !== null && "value" in data) {return (data as { value: string }).value;}throw new Error("Invalid data");}
✅ REQUIRED: Enable strict mode
json
{"compilerOptions": {"strict": true,"noImplicitAny": true,"strictNullChecks": true,"strictFunctionTypes": true}}
✅ REQUIRED: Use proper types for object shapes
typescript
// Interface for extensible objectsinterface User {id: number;name: string;}// Type alias for unions/intersectionstype Status = "pending" | "approved" | "rejected";type UserWithStatus = User & { status: Status };// BAD: Empty object (too permissive)const user: {} = { anything: "allowed" };
✅ REQUIRED: Constrain generics
typescript
// GOOD: Constrained genericfunction getProperty<T extends object, K extends keyof T>(obj: T, key: K): T[K] {return obj[key];}// BAD: Unconstrainedfunction getProperty<T>(obj: T, key: string): any {return obj[key];}
✅ REQUIRED: Use import type for type-only imports
typescript
// GOOD: Separate type importsimport type { User, Product } from "./types";import { fetchUser } from "./api";// GOOD: Inline type keyword when mixing values and typesimport { Installer, type Model } from "../core/installer";// BAD: Types as values (emits unnecessary JS)import { User, Product } from "./types";
✅ REQUIRED: Named imports over namespace imports
typescript
// GOOD: Explicit, tree-shakeableimport { readFileSync, existsSync } from "fs";import { join, resolve } from "path";// BAD: Namespace import when using few exportsimport * as fs from "fs";import * as path from "path";// EXCEPTION: OK when using 6+ exports from one moduleimport * as p from "@clack/prompts";
✅ REQUIRED: No unused code
typescript
// tsconfig.json{"compilerOptions": {"noUnusedLocals": true,"noUnusedParameters": true}}// BAD: Unused import and variableimport { something } from "./lib"; // never usedconst unused = 42;// GOOD: Prefix intentionally unused params with _function handler(_event: Event, data: string) {return data;}
✅ REQUIRED: Use satisfies for type validation without widening
typescript
const config = {endpoint: "/api/users",timeout: 5000,} satisfies Config;// Inferred type + validated against Config
✅ REQUIRED: Use as const for literal types
typescript
const ROUTES = {HOME: "/",ABOUT: "/about",} as const;type Route = (typeof ROUTES)[keyof typeof ROUTES]; // '/' | '/about'
Decision Tree
Runtime validation needed?→ Use form-validation skill (Zod/Yup). TypeScript is compile-time onlyTransforming types?→ See utility-types.md for Partial, Pick, Omit, Record, and 20+ moreUnknown data?→ Use unknown, never any. See type-guards.mdMissing third-party types?→ Install @types/* or declare custom types in types/Importing types only?→ Use import type { ... } or inline type keywordUsing <6 exports from a module?→ Named imports: import { x, y } from 'mod'Unused import/variable?→ Delete it. Enable noUnusedLocals/noUnusedParameters in tsconfigComplex object shape?→ interface for extensibility, type for unions/intersections/computedReusable logic across types?→ See generics-advanced.mdExternal API response?→ Define interface from actual response shape. Use quicktype for generationNew project setup?→ See config-patterns.mdType-safe error handling?→ See error-handling.md
Example
typescript
interface User {id: number;name: string;email: string;}type UserUpdate = Partial<Pick<User, "name" | "email">>;function updateUser<T extends User>(user: T, updates: UserUpdate): T {return { ...user, ...updates };}const result: User = updateUser({ id: 1, name: "John", email: "john@example.com" },{ name: "Jane" },);
Edge Cases
Discriminated unions for type narrowing:
typescript
type Result =| { success: true; data: string }| { success: false; error: Error };function handle(result: Result) {if (result.success) {console.log(result.data); // TypeScript knows data exists}}
Custom type guards:
typescript
function isUser(value: unknown): value is User {return typeof value === "object" && value !== null && "id" in value;}
- Circular types: Extract shared interfaces or use type parameters.
- Index signatures:
Record<string, Type>for dynamic keys; mapped types for known keys. - Const assertions:
as constcreates readonly literal types.
Checklist
- [ ]
strict: trueintsconfig.json - [ ] No
anyusage -- useunknownwith type guards - [ ]
import typefor type-only imports (or inlinetypekeyword) - [ ] Named imports over namespace imports (
import { x }notimport * as) - [ ] No unused imports, variables, or parameters (
noUnusedLocals,noUnusedParameters) - [ ] Interfaces for object shapes, type aliases for unions/intersections
- [ ] Generics constrained with
extends - [ ]
satisfiesfor validation without type widening - [ ]
as constfor literal inference
Resources
- references/ -- utility types, generics, type guards, config patterns, error handling
- TypeScript Docs
- TSConfig Reference