⌨️ Codingintermediatetypescripttypesinterfacesgenericsfrontend

Write TypeScript Types and Interfaces

Generate precise TypeScript types, interfaces, generics, and utility types for any data structure.

The Prompt

prompt.txt
Write TypeScript types/interfaces for the following data structures. Include:
1. Main interface/type definitions
2. Any useful generic variants
3. Utility types derived from the main types (Pick, Omit, Partial variants)
4. Type guards where appropriate
5. JSDoc comments for each type

Data to type:
[DESCRIBE YOUR DATA — e.g., An API response that can be either a success with a typed payload or an error with a code and message. The payload type should be generic. There's also a paginated variant that wraps any list response.]

Existing types to extend from (if any):
[PASTE EXISTING TYPES]

Example Output

Defined a generic `ApiResponse<T>` discriminated union with `{ success: true; data: T }` and `{ success: false; error: ApiError }` variants, a `PaginatedResponse<T>` wrapper with cursor-based pagination fields, and a `isSuccess` type guard that narrows correctly.

FAQ

Which AI model is best for Write TypeScript Types and Interfaces?

Claude Sonnet 4 — superior TypeScript type reasoning, especially for complex generics and conditional types.

How do I use the Write TypeScript Types and Interfaces prompt?

Copy the prompt, replace the [BRACKETED] placeholders with your specific information, and paste into your preferred AI assistant (ChatGPT, Claude, Gemini, etc.). Defined a generic `ApiResponse<T>` discriminated union with `{ success: true; data: T }` and `{ success: false; error: ApiError }` variants, a `PaginatedResponse<T>` wrapper with cursor-based pagination fields, and a `isSuccess` type guard that narrows correctly.