一键导入
typescript-types
Define TypeScript types, interfaces, and type utilities. Use when creating type definitions, DTOs, API response types, or component props.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Define TypeScript types, interfaces, and type utilities. Use when creating type definitions, DTOs, API response types, or component props.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Create robust, error-proof Prisma seed scripts with comprehensive error handling and validation.
Create Next.js 16 API Route Handlers. Use when building REST endpoints (GET, POST, PUT, DELETE), implementing CRUD operations, or creating authenticated APIs with Zod validation.
Create React/Next.js 16 components. Use when building pages, client/server components, forms with useActionState, or UI with shadcn/ui. ALWAYS activate with frontend-design together.
Unit tests with Jest + React Testing Library. CRITICAL - Uses Jest (NOT Vitest).
Write integration tests with Jest for API routes and database operations. Use when testing backend logic, API endpoints, or data layer.
Review code for quality, security, performance, and best practices. Use when reviewing changes before commit, auditing code for issues, or suggesting improvements.
| name | typescript-types |
| description | Define TypeScript types, interfaces, and type utilities. Use when creating type definitions, DTOs, API response types, or component props. |
This skill guides creation of TypeScript types and interfaces for Next.js applications.
src/types/ or src/types/index.tsindex.ts to re-export all types| Type | Convention | Example |
|---|---|---|
| Entity interfaces | PascalCase | Book, User, Order |
| Display/Card types | Entity + Data/Card suffix | BookCardData, UserProfile |
| API response types | Action + Response | LoginResponse, SearchResult |
| Props types | ComponentName + Props | BookCardProps, HeaderProps |
| Enums | PascalCase | OrderStatus, UserRole |
// src/types/index.ts
export interface Book {
id: string;
title: string;
author: string;
price: number;
stock: number;
coverUrl?: string;
createdAt: Date;
updatedAt: Date;
}
export interface Category {
id: string;
name: string;
slug: string;
parentId?: string;
}
// Subset of entity for display purposes
export interface BookCardData {
id: string;
title: string;
author: string;
price: number;
coverUrl?: string;
rating?: number;
discountPercent?: number;
}
export interface CategoryWithCount {
id: string;
name: string;
slug: string;
bookCount: number;
coverImage?: string;
}
// Generic API response wrapper
export interface ApiResponse<T> {
success: boolean;
data?: T;
error?: {
code: string;
message: string;
};
}
// Paginated response
export interface PaginatedResponse<T> {
items: T[];
total: number;
page: number;
pageSize: number;
totalPages: number;
}
// Specific responses
export interface SearchBooksResponse {
books: BookCardData[];
total: number;
query: string;
}
// Props with children
export interface CardProps {
children: React.ReactNode;
className?: string;
}
// Props with data
export interface BookCardProps {
book: BookCardData;
onAddToCart?: (id: string) => void;
showRating?: boolean;
}
// Props with handlers
export interface SearchBarProps {
placeholder?: string;
onSearch: (query: string) => void;
onClear?: () => void;
}
// Use const objects for better tree-shaking
export const OrderStatus = {
PENDING: 'pending',
CONFIRMED: 'confirmed',
SHIPPED: 'shipped',
DELIVERED: 'delivered',
CANCELLED: 'cancelled',
} as const;
export type OrderStatus = typeof OrderStatus[keyof typeof OrderStatus];
// Simple union types
export type SortOrder = 'asc' | 'desc';
export type BookSortBy = 'price' | 'title' | 'createdAt' | 'rating';
// Entity to display type conversion
export function toBookCardData(book: Book): BookCardData {
return {
id: book.id,
title: book.title,
author: book.author,
price: book.price,
coverUrl: book.coverUrl,
};
}
// Batch conversion
export function toBooksCardData(books: Book[]): BookCardData[] {
return books.map(toBookCardData);
}
src/types/index.ts for easy importsinterface for objects, type for unions/primitives? suffixany - use unknown if type is truly unknown