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 →
Popular Tags:
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
No Prompts Found
Try adjusting your filters or search query.
Want Custom Prompts?
Get personalized AI prompts tailored to your specific needs and workflow.
Contact Us