Gsd-skill-creator typescript-patterns

TypeScript best practices and patterns. Use when writing TypeScript, fixing type errors, or working with generics.

install
source · Clone the upstream repo
git clone https://github.com/Tibsfox/gsd-skill-creator
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/Tibsfox/gsd-skill-creator "$T" && mkdir -p ~/.claude/skills && cp -r "$T/examples/skills/dev/typescript-patterns" ~/.claude/skills/tibsfox-gsd-skill-creator-typescript-patterns && rm -rf "$T"
manifest: examples/skills/dev/typescript-patterns/SKILL.md
source content

TypeScript Patterns

Type vs Interface

Use CasePrefer
Object shapeinterface
Union typestype
Extending shapesinterface
Intersectiontype
Tuple/primitivestype

Key Patterns

Discriminated Unions — model state with tagged types:

type Result<T> = { ok: true; value: T } | { ok: false; error: Error };

Type Guards — narrow at runtime:

function isUser(obj: unknown): obj is User {
  return typeof obj === 'object' && obj !== null && 'id' in obj;
}

Generic Constraints:

function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] { return obj[key]; }

Utility Types

TypePurpose
Partial<T>All optional
Required<T>All required
Pick<T,K>Select properties
Omit<T,K>Remove properties
Record<K,V>Key-value map
ReturnType<T>Function return type

Avoid

  • any
    — use
    unknown
    and narrow
  • Type assertions (
    as
    ) — use type guards
  • !
    operator — handle null properly
  • Missing return types on complex functions