AI Prompts Library

Curated collection of expert prompts for coding, writing, marketing, image generation, and more

Have a great prompt? Submit it to the library →

Coding

TypeScript Type Generator from JSON

Optimized for: general • TEXT
You are a TypeScript expert. Given a JSON sample (API response, config file, or data structure), generate comprehensive TypeScript type definitions.

**JSON Input:**
```json
[PASTE YOUR JSON HERE]
```

**Context:** [Is this an API response? Config file? Database record? Describe the data.]

**Generation Rules:**

1. **Type Inference:**
   - Analyze all values to determine the most specific type
   - Detect nullable fields (present but null in the sample)
   - Identify optional fields (might not always be present)
   - Recognize enum-like values (status: "active" | "inactive" | "pending")
   - Detect date strings and type them as `string` with JSDoc annotation
   - Handle arrays: determine if homogeneous or tuple

2. **Naming Conventions:**
   - PascalCase for interface/type names
   - camelCase for properties
   - Descriptive names based on the data context
   - Suffix with Response, Request, Config, etc. as appropriate

3. **Output Format:**
   - Use `interface` for object shapes (extendable)
   - Use `type` for unions, intersections, and utility types
   - Export all types
   - Add JSDoc comments explaining each field
   - Group related types in a logical order
   - Create a namespace or module if there are many types

4. **Additional Types:**
   - Generate a Zod schema that matches the TypeScript types (for runtime validation)
   - Create Pick/Omit utility types for common subsets (e.g., CreateInput = Omit<User, 'id' | 'createdAt'>)
   - Generate a mock data factory function for testing

5. **Edge Cases:**
   - Handle deeply nested objects by creating separate interfaces
   - Handle polymorphic arrays with discriminated unions
   - Add index signatures for dynamic keys
   - Handle BigInt, Date, and other special types

**Output**: Complete .d.ts or .ts file with all types, Zod schemas, and mock factory.

Converting API responses to TypeScript types, creating type-safe data layers, schema generation

Coding

API Error Response Designer

Optimized for: gpt-4o • TEXT
Design comprehensive API error response:

```json
{
  "error": {
    "code": "ERROR_CODE",
    "message": "Human-readable error message",
    "details": "Detailed explanation",
    "timestamp": "2025-10-02T02:00:00Z",
    "request_id": "uuid",
    "documentation_url": "https://docs.example.com/errors/ERROR_CODE",
    "field_errors": [
      {
        "field": "email",
        "message": "Invalid email format",
        "code": "INVALID_FORMAT"
      }
    ]
  }
}
```

**Error Categories**:
- 4xx Client Errors: Authentication, validation, not found
- 5xx Server Errors: Internal, service unavailable, timeout

**Best Practices**:
- Use consistent error codes
- Provide actionable messages
- Include request tracking
- Add documentation links
- Never expose sensitive data

API development, error handling, developer experience

Want Custom Prompts?

Get personalized AI prompts tailored to your specific needs and workflow.

Contact Us