К основному содержанию
скилл CX Codex

typescript-core — скилл для Claude Code: паттерны TypeScript

Скилл с современными паттернами TypeScript: строгий tsconfig, валидация данных во время выполнения, продвинутые типы. Пригодится, когда проект на TS растёт и типы перестают спасать.

Установить в Claude Code · Через Skills CLI (Vercel) Все способы и платформы ↓
npx skills add bobmatnyc/claude-mpm-skills --skill typescript-core -a claude-code
Открыть на GitHub

Что делает typescript-core

Скилл описывает, как настроить TypeScript-проект: базовый tsconfig.json с strict, noUncheckedIndexedAccess, exactOptionalPropertyTypes и verbatimModuleSyntax, плюс разбор ключевых опций компилятора и когда их включать. Дальше идут паттерны типов — const type parameters, оператор satisfies, template literal types, размеченные объединения с проверкой исчерпываемости.

Отдельный блок про валидацию во время выполнения: типы TypeScript исчезают в рантайме, поэтому для данных из API, форм и конфигов предлагается Zod, TypeBox или Valibot с таблицей сравнения по размеру бандла и скорости. Есть раздел с деревьями решений (type против interface, дженерики против объединений) и разбор частых ошибок компиляции.

Внутри — точка входа с кратким обзором и набор справочных файлов: advanced-types.md, configuration.md, runtime-validation.md, advanced-patterns-2025.md, decision-trees.md, troubleshooting.md, js-quality-antipatterns.md. Скилл не вызывается пользователем напрямую и отключает вызов моделью, так что подключается как справочник, а не как команда. Ориентирован на TS 5.2 и новее — на более старых версиях часть примеров с using и декораторами не соберётся.

Какие задачи решает

  • включить строгий режим в существующем проекте без лавины ошибок
  • заменить any на unknown в местах разбора внешних данных
  • выбрать библиотеку валидации под размер бандла
  • сохранить литеральные типы в конфиге через satisfies
  • разобраться, почему компиляция идёт медленно

Примеры запросов агенту

  • Настрой tsconfig для нового TypeScript-проекта по паттернам typescript-core
  • Проверь этот файл на антипаттерны из typescript-core
  • Помоги выбрать между Zod и TypeBox для валидации ответов API

Как установить typescript-core

1Через Skills CLI (Vercel)

npx skills add bobmatnyc/claude-mpm-skills --skill typescript-core -a claude-code

2Вручную: положить файлы

~/.claude/skills/typescript-core/SKILL.md

Папка скилла целиком; для одного проекта — .claude/skills/typescript-core/

По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов

Из того же набора65

git-workflow Скилл с готовыми Git-паттернами: коммиты, ветки, конфликты, rebase и хуки. Пригодится, когда агент трогает версионирование. CX Codex +1 556установок zustand Скилл по zustand: минимальный стейт-менеджер для React на хуках, без провайдеров и лишнего кода. Пригодится, когда глобальное состояние нужно, а Redux не хочется. CX Codex +1 485установок hono-core Скилл по Hono: маршрутизация, контекст, обработчики и ответы для одного кода на Cloudflare Workers, Deno, Bun и Node.js. CX Codex +1 483установок asyncio Скилл по Python asyncio: корутины, задачи, event loop, aiohttp и асинхронные эндпоинты FastAPI. Пригодится, когда код ждёт сеть или базу. CX Codex +1 476установок celery Скилл по Celery: фоновые задачи, периодические джобы и цепочки воркеров на Python. Пригодится, когда длинные операции надо унести из веб-запроса. CX Codex +1 454установок golang-testing-strategies Скилл для написания тестов на Go: табличные тесты, testify, gomock, бенчмарки и покрытие в CI. Пригодится, когда нужно навести порядок в тестовом наборе проекта. CX Codex +1 443установок sveltekit Скилл подсказывает агенту, как устроен SvelteKit: файловый роутинг, load-функции, form actions и адаптеры для деплоя. CX Codex +1 441установок wordpress-advanced-architecture Скилл по продвинутой разработке под WordPress: свои REST-маршруты, команды WP-CLI, кэширование транзиентами и объектным кэшем. CX Codex +1 441установок

Похожие

fastify-typescript Mindrally Задаёт агенту соглашения по Fastify и TypeScript: схемы валидации, плагины, Prisma и тесты через Jest. Пригодится, когда пишете типизированный REST API. CX Codex +1 856установок typescript-pro https://github.com/Jeffallan Настраивает строгую типизацию TypeScript, генерирует брендированные типы и связывает tRPC. Пригодится при проектировании надёжных API и сложных generic-структур. CX Codex +1 14 200установок typescript PyModel Скилл с 44 правилами по типам, tsconfig и async-коду. Пригодится, когда агент правит конфиг компилятора или разбирает сложные дженерики. CX Codex +1 520установок typescript-mcp-server-generator официальный github Генерирует TypeScript-проект MCP-сервера с инструментами, ресурсами и конфигурацией. Пригодится, когда нужно быстро заложить сервер на MCP TypeScript SDK v2. 12 050установок express-typescript Mindrally Правила для агента, который пишет API на Express.js и TypeScript: структура проекта, middleware, валидация и безопасность. CX Codex +1 1 400установок zod-validation-utilities giuseppe-trisciuoglio Помогает писать схемы Zod v4 для проверки API, форм и конфигурации в TypeScript. Пригодится для разбора внешних данных и понятной обработки ошибок. CX Codex +1 3 800установок

Рядом в теме «Языки программирования»

Все скиллы по теме «Языки программирования» →

Вопросы о typescript-core

Как установить typescript-core в Claude?

Выполните npx skills add bobmatnyc/claude-mpm-skills --skill typescript-core -a claude-code. Файл скилла окажется по пути ~/.claude/skills/typescript-core/SKILL.md.

Что делает typescript-core?

Собирает паттерны TypeScript: базовый tsconfig, продвинутые типы, валидацию данных в рантайме и деревья решений. Работает как справочник, который агент подтягивает по необходимости.

Для каких версий TypeScript подходит скилл?

Материал рассчитан на TS 5.2 и новее. Примеры с using и декораторами на старых версиях не скомпилируются.

Исходный текст

SKILL.md · MIT
---
name: typescript-core
description: "Advanced TypeScript patterns and best practices for 2025"
user-invocable: false
disable-model-invocation: true
version: 1.2.0
updated: "2026-06-15"
progressive_disclosure:
  entry_point:
    summary: "Type-safe TypeScript patterns with optimal tsconfig, runtime validation, and modern TS 5.2+ features"
    when_to_use: "When working with TypeScript requiring advanced types, strict configuration, runtime validation, or modern language features (using, decorators)"
    quick_start: "1. Start with tsconfig baseline 2. Apply core type patterns (const, satisfies) 3. Integrate runtime validation (Zod/TypeBox) 4. Use modern features (using, decorators) as needed"
  references:
    - advanced-types.md
    - configuration.md
    - runtime-validation.md
    - advanced-patterns-2025.md
    - decision-trees.md
    - troubleshooting.md
    - js-quality-antipatterns.md
---

# TypeScript Core Patterns

Modern TypeScript development patterns for type safety, runtime validation, and optimal configuration.

## Quick Start

**New Project:** Use 2025 tsconfig → Enable `strict` + `noUncheckedIndexedAccess` → Choose Zod for validation

**Existing Project:** Enable `strict: false` initially → Fix `any` with `unknown` → Add `noUncheckedIndexedAccess`

**API Development:** Zod schemas at boundaries → `z.infer<typeof Schema>` for types → `satisfies` for routes

**Library Development:** Enable `declaration: true` → Use `const` type parameters → See [advanced-patterns-2025.md](./references/advanced-patterns-2025.md)

## Quick Reference

### tsconfig.json 2025 Baseline

```json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "strict": true,
    "noUncheckedIndexedAccess": true,
    "exactOptionalPropertyTypes": true,
    "verbatimModuleSyntax": true,
    "isolatedModules": true,
    "skipLibCheck": true,
    "declaration": true,
    "declarationMap": true
  }
}
```

### Key Compiler Options

| Option | Purpose | When to Enable |
|--------|---------|----------------|
| `noUncheckedIndexedAccess` | Forces null checks on array/object access | Always for safety |
| `exactOptionalPropertyTypes` | Distinguishes `undefined` from missing | APIs with optional fields |
| `verbatimModuleSyntax` | Enforces explicit type-only imports | ESM projects |
| `erasableSyntaxOnly` | Node.js 22+ native TS support | Type stripping environments |

## Local Baselines

See `references/configuration.md` for repo-specific tsconfig patterns (CommonJS CLI, NodeNext strict, Next.js bundler).

## Core Type Patterns

### Const Type Parameters

Preserve literal types through generic functions:

```typescript
function createConfig<const T extends Record<string, unknown>>(config: T): T {
  return config;
}

const config = createConfig({ 
  apiUrl: "https://api.example.com", 
  timeout: 5000 
});
// Type: { readonly apiUrl: "https://api.example.com"; readonly timeout: 5000 }
```

### Satisfies Operator

Validate against a type while preserving literal inference:

```typescript
type Route = { path: string; children?: Routes };
type Routes = Record<string, Route>;

const routes = {
  AUTH: { path: "/auth" },
  HOME: { path: "/" }
} satisfies Routes;

routes.AUTH.path;     // Type: "/auth" (literal preserved)
routes.NONEXISTENT;   // ❌ Type error
```

### Template Literal Types

Type-safe string manipulation and route extraction:

```typescript
type ExtractParams<T extends string> = 
  T extends `${string}:${infer Param}/${infer Rest}`
    ? Param | ExtractParams<Rest>
    : T extends `${string}:${infer Param}`
      ? Param
      : never;

type Params = ExtractParams<"/users/:id/posts/:postId">; // "id" | "postId"
```

### Discriminated Unions with Exhaustiveness

```typescript
type Result<T, E = Error> = 
  | { success: true; data: T }
  | { success: false; error: E };

function handleResult<T>(result: Result<T>): T {
  if (result.success) return result.data;
  throw result.error;
}

// Exhaustiveness checking
type Action = 
  | { type: 'create'; payload: string }
  | { type: 'delete'; id: number };

function handle(action: Action) {
  switch (action.type) {
    case 'create': return action.payload;
    case 'delete': return action.id;
    default: {
      const _exhaustive: never = action;
      throw new Error(`Unhandled: ${_exhaustive}`);
    }
  }
}
```

## Runtime Validation

TypeScript types disappear at runtime. Use validation libraries for external data (APIs, forms, config files).

### Quick Comparison

| Library | Bundle Size | Speed | Best For |
|---------|-------------|-------|----------|
| **Zod** | ~13.5kB | Baseline | Full-stack apps, tRPC integration |
| **TypeBox** | ~8kB | ~10x faster | OpenAPI, performance-critical |
| **Valibot** | ~1.4kB | ~2x faster | Edge functions, minimal bundles |

### Basic Pattern (Zod)

```typescript
import { z } from "zod";

const UserSchema = z.object({
  id: z.string().uuid(),
  email: z.string().email(),
  role: z.enum(["admin", "user", "guest"]),
});

type User = z.infer<typeof UserSchema>;

// Validate external data
function parseUser(input: unknown): User {
  return UserSchema.parse(input);
}
```

**→ See [runtime-validation.md](./references/runtime-validation.md) for complete Zod, TypeBox, and Valibot patterns**

## Decision Support

### Quick Decision Guide

**Need to choose between `type` vs `interface`?**
- Public API / library types → `interface`
- Union types / mapped types → `type`
- Simple object shapes → `interface` (default)

**Need generics or union types?**
- Output type depends on input type → Generics
- Fixed set of known types → Union types
- Building reusable data structures → Generics

**Dealing with unknown data?**
- External data (API, user input) → `unknown` (type-safe)
- Rapid prototyping / migration → `any` (temporarily)

**Need runtime validation?**
- Full-stack TypeScript with tRPC → Zod
- OpenAPI / high performance → TypeBox
- Edge functions / minimal bundle → Valibot

**→ See [decision-trees.md](./references/decision-trees.md) for comprehensive decision frameworks**

## Troubleshooting

### Common Issues Quick Reference

**Property does not exist on type** → Define proper interface or use optional properties

**Type is not assignable** → Fix property types or use runtime validation (Zod)

**Object is possibly 'undefined'** → Use optional chaining (`?.`) or type guards

**Cannot find module** → Check file extensions (.js for ESM) and module resolution

**Slow compilation** → Enable `incremental`, use `skipLibCheck`, consider esbuild/swc

**→ See [troubleshooting.md](./references/troubleshooting.md) for detailed solutions with examples**

## Navigation

### Detailed References

- **[📐 Advanced Types](./references/advanced-types.md)** - Conditional types, mapped types, infer keyword, recursive types. Load when building complex type utilities or generic libraries.

- **[⚙️ Configuration](./references/configuration.md)** - Complete tsconfig.json guide, project references, monorepo patterns. Load when setting up new projects or optimizing builds.

- **[🔒 Runtime Validation](./references/runtime-validation.md)** - Zod, TypeBox, Valibot deep patterns, error handling, integration strategies. Load when implementing API validation or form handling.

- **[✨ Advanced Patterns 2025](./references/advanced-patterns-2025.md)** - TypeScript 5.2+ features: `using` keyword, stable decorators, import type behavior, satisfies with generics. Load when using modern language features.

- **[🌳 Decision Trees](./references/decision-trees.md)** - Clear decision frameworks for `type` vs `interface`, generics vs unions, `unknown` vs `any`, validation library selection, type narrowing strategies, and module resolution. Load when making TypeScript design decisions.

- **[🔧 Troubleshooting](./references/troubleshooting.md)** - Common TypeScript errors and fixes, type inference issues, module resolution problems, tsconfig misconfigurations, build performance optimization, and type compatibility errors. Load when debugging TypeScript issues.

## JavaScript / Runtime Quality Anti-Patterns

The type system catches type errors, but a class of JavaScript defects is **runtime/AST-
level** and survives into emitted JS and plain-JS files. Watch for:

- **Loose equality** (`==`/`!=`) — coercion bugs and auth flaws; use `===`/`!==` (accept
  `== null` only when commented as "null or undefined").
- **Dynamic code execution** (`eval`, `new Function(str)`, string `setTimeout`) — injection
  risk and unnecessary; use direct syntax.
- **Mutating builtins** (`Object`/`Array`/`Function.prototype`) — pollutes `for…in`,
  breaks the whole runtime; extend or use free functions instead.
- **Variable shadowing**, **`var` instead of `let`/`const`**, **using functions before
  declaration** — readability and "wrong variable" bugs.
- **Logical OR in `switch` case labels** (`case 1 || 2:` only matches 1) — use stacked
  case labels.
- **Repetitive deep-member access** — cache the resolved chain in a local (esp. DOM).
- **Non-wrapped IIFEs**, **backslash multiline strings**, **`new Array()`** — readability
  and well-known traps; prefer wrapped IIFEs, template literals, and array literals.

See **[JS/TS Quality Anti-Patterns](./references/js-quality-antipatterns.md)** for each
defect with compliant/non-compliant examples, severities, false-positive filters, and the
equivalent ESLint/SonarSource rule. Derived from CAST Highlight JavaScript code quality
indicators (https://doc.casthighlight.com/), cross-referenced to ESLint core rules and
SonarSource RSPEC.

## Red Flags

**Stop and reconsider if:**
- Using `any` instead of `unknown` for external data
- Casting with `as` without runtime validation
- Disabling strict mode for convenience
- Using `@ts-ignore` without clear justification
- Index access without `noUncheckedIndexedAccess`

## Integration with Other Skills

- **nextjs-core**: Type-safe Server Actions and route handlers
- **nextjs-v16**: Async API patterns and Cache Components typing
- **mcp-builder**: Zod schemas for MCP tool inputs

## Related Skills

When using Core, these skills enhance your workflow:
- **react**: TypeScript with React: component typing, hooks, generics
- **nextjs**: TypeScript in Next.js: Server Components, Server Actions typing
- **drizzle**: Type-safe database queries with Drizzle ORM
- **prisma**: Prisma's generated TypeScript types for database schemas

[Full documentation available in these skills if deployed in your bundle]

© bobmatnyc · MIT · bobmatnyc/claude-mpm-skills

Смотрите также

Спонсоры проекта

Компании, которые помогают держать аналитику открытой