Skip to content
Back to skills

Typescript Patterns

ASecurity

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

  • 72 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 6, 2026
ai-agentstypescriptgo

Security analysis

A100/100

Scanned September 6, 2026

npx -y skills add Tibsfox/gsd-skill-creator --skill typescript-patterns --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Typescript Patterns?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Typescript Patterns
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tibsfox-typescript-patterns-gsd-skill-creator/badge)](https://www.skillsdirectory.com/skills/tibsfox-typescript-patterns-gsd-skill-creator)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: typescript-patterns
description: TypeScript best practices and patterns. Use when writing TypeScript, fixing type errors, or working with generics.
type: skill
category: dev
status: stable
origin: tibsfox
modified: false
first_seen: 2026-01-30
first_path: examples/typescript-patterns/SKILL.md
superseded_by: null
---
# TypeScript Patterns

## Type vs Interface

| Use Case | Prefer |
|----------|--------|
| Object shape | interface |
| Union types | type |
| Extending shapes | interface |
| Intersection | type |
| Tuple/primitives | type |

## Key Patterns

**Discriminated Unions** — model state with tagged types:
```typescript
type Result<T> = { ok: true; value: T } | { ok: false; error: Error };
```

**Type Guards** — narrow at runtime:
```typescript
function isUser(obj: unknown): obj is User {
  return typeof obj === 'object' && obj !== null && 'id' in obj;
}
```

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

## Utility Types

| Type | Purpose |
|------|---------|
| 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

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.