π¦ ClawHub
TypeScript
by @ivangdavila
Write type-safe TypeScript with proper narrowing, inference patterns, and strict mode best practices.
TERMINAL
clawhub install typescriptπ About This Skill
name: TypeScript slug: typescript version: 1.0.2 description: Write type-safe TypeScript with proper narrowing, inference patterns, and strict mode best practices.
When to Use
User needs TypeScript expertise β from basic typing to advanced generics. Agent handles type narrowing, inference, discriminated unions, and strict mode patterns.
Quick Reference
| Topic | File |
|-------|------|
| Generic patterns | generics.md |
| Utility types | utility-types.md |
| Declaration files | declarations.md |
| Migration from JS | migration.md |
Stop Using any
unknown forces you to narrow before use β any silently breaks type safetyunknown, never anyunknown, not anyNarrowing Failures
filter(Boolean) doesn't narrow β use .filter((x): x is T => Boolean(x))Object.keys(obj) returns string[], not keyof typeof obj β intentional, objects can have extra keysArray.isArray() narrows to any[] β may need assertion for element typein operator narrows but only if property is in exactly one branch of unionLiteral Type Traps
let x = "hello" is string β use const or as const for literal type{ status: "ok" } has status: string β use as const or type annotationInference Limits
fn() can't infer, pass a value or annotateDiscriminated Unions
type or kind field to each variant β enables exhaustive switchdefault: const _never: never = x β compile error if case missedsatisfies vs Type Annotation
const x: Type = val widens to Type β loses literal infoconst x = val satisfies Type keeps literal, checks compatibility β prefer for config objectsStrict Null Handling
?. returns undefined, not null β matters for APIs expecting null?? only catches null/undefined β || catches all falsy including 0 and ""! should be last resort β prefer narrowing or early returnModule Boundaries
import type for type-only imports β stripped at runtime, avoids bundler issuesexport type { X } β prevents accidental runtime dependency.d.ts augmentation: use declare module with exact module pathβ‘ When to Use
User needs TypeScript expertise β from basic typing to advanced generics. Agent handles type narrowing, inference, discriminated unions, and strict mode patterns.