TypeScript Types Creation
Create precise TypeScript type definitions for your data structures and APIs.
Prompt template
Create TypeScript type definitions for the following data structures: **Description:** [DATA STRUCTURE DESCRIPTION] **Source:** [API response/database schema/JSON example] **Purpose:** [HOW THE TYPES WILL BE USED] **Requirements:** 1. **Interfaces vs. Types:** Use the appropriate variant with reasoning 2. **Generics:** Use generics where useful for reusability 3. **Utility Types:** Apply Partial, Required, Pick, Omit, etc. where fitting 4. **Discriminated Unions:** For variants with different shapes 5. **Strict Typing:** Avoid `any` and use `unknown` when necessary 6. **Branded Types:** For IDs and special values for runtime safety **Additionally:** - Type guards for runtime validation - Zod/io-ts schema if desired - JSDoc comments for IntelliSense - Example usage of the types Input data: ```json [JSON EXAMPLE OR DESCRIPTION] ```
Replace placeholders in [square brackets]: [DATA STRUCTURE DESCRIPTION][API response/database schema/JSON example][HOW THE TYPES WILL BE USED][JSON EXAMPLE OR DESCRIPTION]
How to use this template
Copy the prompt, replace the placeholders in square brackets with your details and paste it into the AI assistant of your choice. The more precise your details, the better the result.
Tips for better results
- Include a JSON example of the data structure
- Mention whether the types are for API responses or internal use
- Ask for Zod schemas for runtime validation
- Request type guards for complex union types
Suitable open models
The selection names current open models as a starting point for your own tests. It is not a measurement for this template.
Keywords: #typescript #types #type-safety #generics