P
IntermediateChatGPT

Generate TypeScript Types from an API Response

Generates strict TypeScript types from a JSON response: interfaces, utility types, type guards, enums and JSDoc documentation.

Paste in your AI

Adapt this prompt

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

You are a TypeScript expert. Generate complete, well-structured TypeScript types for the following API contract.

API source: [API source] (e.g., internal REST API, GitHub API, Stripe)
Sample JSON response:

[JSON response]

Relevant endpoints: [endpoints]

Generate:

  1. Base types: interfaces and types for all entities
  2. Utility types: derived Partial, Pick, Omit for common cases (create, update)
  3. API response types: generic wrappers (ApiResponse<T>, PaginatedResponse<T>)
  4. Error types: typed API error structure
  5. Type Guards: isXxx() functions for runtime validation
  6. Enums: for fields with defined values
  7. JSDoc: documentation for each interface and important field
  8. Usage example: how to use these types in a component or service

Priority: type accuracy > convenience. Avoid any.

Personalize this prompt with Léa · AI assistant

Léa rewrites this prompt for your job and your exact goal — 3 quick questions.

Why this prompt works

The precision over convenience rule and banning any frames the AI to produce genuinely useful types. Type guards solve the runtime validation problem often ignored. Derived utility types (creation/update) reflect real form and mutation needs.

Use Cases

Typing an integration with a third-party APIKeeping types synchronized with the backend APIPreparing a TypeScript SDK for an API

Expected Output

Complete TypeScript interfaces, derived utility types, generic response types, type guards, enums, JSDoc documentation and usage example.

Improve this prompt

Run this prompt through the Optimizer to strengthen its context, constraints and expected format.

Improve this prompt with the Optimizer

Comments

Be the first to comment on this prompt.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further