generating-typescript-types-from-apis
БесплатноБез исполняемых скриптовНе проверенGenerates TypeScript interfaces from API responses or OpenAPI schemas. Use when the user asks about typing API responses, creating interfaces from JSON…
от diegosouzapw★ 68 звёзд на GitHubОб этом скилле
API Response → TypeScript Types
When to use this skill
- User asks to type an API response
- User has JSON and needs TypeScript interfaces
- User mentions OpenAPI or Swagger schemas
- User wants to generate types from endpoints
- User asks about keeping frontend/backend types in sync
Workflow
- Identify API source (JSON response, OpenAPI, endpoint)
- Parse response structure
- Generate TypeScript interfaces
- Handle nested objects and arrays
- Add JSDoc comments
- Export types to appropriate location
Instructions
Step 1: Identify Source Type
| Source | Approach |
|---|---|
| JSON response | Parse and infer types |
| OpenAPI/Swagger | Use generator tool |
| GraphQL | Use codegen |
| Live endpoint | Fetch and parse |
Step 2: Parse JSON Response
Sample API response:
{
"id": 123,
"name": "John Doe",
"email": "[email protected]",
"isActive": true,
"roles": ["admin", "user"],
"profile": {
"avatar": "https://example.com/avatar.jpg",
"bio": null,
"socialLinks": [
{ "platform": "twitter", "url": "https://twitter.com/john" }
]
},
"createdAt": "2026-01-18T10:00:00Z",
"metadata": {}
}
Generated TypeScript:
// types/api/user.ts
export interface User {
/** Unique identifier */
id: number;
/** User's full name */
name: string;
/** Email address */
email: string;
/** Whether the user account is active */
isActive: boolean;
/** Assigned roles */
roles: string[];
/** User profile information */
profile: UserProfile;
/** Account creation timestamp (ISO 8601) */
createdAt: string;
/** Additional metadata */
metadata: Record<string, unknown>;
}
export interface UserProfile {
/** Avatar image URL */
avatar: string;
/** User biography */
bio: string | null;
/** Social media links */
socialLinks: SocialLink[];
}
export interface SocialLink {
/** Platform name */
platform: string;
/** Profile URL */
url: string;
}
Step 3: Type Inference Rules
| JSON Value | TypeScript Type |
|---|---|
123 |
number |
"text" |
string |
true/false |
boolean |
null |
null (or T | null) |
[] |
T[] (infer from items) |
{} empty |
Record<string, unknown> |
{} with keys |
Named interface |
| ISO date string | string (add comment) |
| UUID string | string (add branded type) |
Branded types for special strings:
// types/branded.ts
export type UUID = string & { readonly __brand: "UUID" };
export type ISODateString = string & { readonly __brand: "ISODateString" };
export type Email = string & { readonly __brand: "Email" };
// Usage
export interface User {
id: UUID;
email: Email;
createdAt: ISODateString;
}
Step 4: Handle Arrays
Homogeneous array:
// JSON: [1, 2, 3]
items: number[];
// JSON: ["a", "b"]
tags: string[];
Array of objects:
// JSON: [{ "id": 1, "name": "Item" }]
items: Item[];
interface Item {
id: number;
name: string;
}
Mixed array (avoid if possible):
// JSON: [1, "two", true]
values: (number | string | boolean)[];
Tuple (fixed length, known types):
// JSON: [37.7749, -122.4194] (lat/lng)
coordinates: [number, number];
Step 5: Handle Optional Fields
Detect optional fields from multiple samples:
// Sample 1: { "name": "John", "nickname": "Johnny" }
// Sample 2: { "name": "Jane" }
export interface User {
name: string;
nickname?: string; // Optional - not present in all responses
}
Nullable vs optional:
export interface User {
bio: string | null; // Present but can be null
nickname?: string; // May not be present
avatar?: string | null; // May not be present, or null
}
Step 6: API Response Wrappers
Paginated response:
export interface PaginatedResponse<T> {
data: T[];
pagination: {
page: number;
perPage: number;
total: number;
totalPages: number;
};
}
// Usage
type UsersResponse = PaginatedResponse<User>;
API envelope:
export interface ApiResponse<T> {
success: boolean;
data: T;
error?: ApiError;
}
export interface ApiError {
code: string;
message: string;
details?: Record<string, string[]>;
}
// Usage
type UserResponse = ApiResponse<User>;
type UsersResponse = ApiResponse<User[]>;
Step 7: OpenAPI/Swagger Generation
Using openapi-typescript:
npm install -D openapi-typescript
# From URL
npx openapi-typescript https://api.example.com/openapi.json -o types/api.ts
# From local file
npx openapi-typescript ./openapi.yaml -o types/a
Установить generating-typescript-types-from-apis в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл generating-typescript-types-from-apis?
Generates TypeScript interfaces from API responses or OpenAPI schemas. Use when the user asks about typing API responses, creating interfaces from JSON, parsing Swagger/OpenAPI, or keeping types in sync with backend.
Как установить скилл generating-typescript-types-from-apis?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл generating-typescript-types-from-apis запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic