TypeScript Interface Generator Prompt

Generate precise TypeScript interfaces and related types from sample data or a verified schema, with explicit nullability, unions, runtime-boundary notes, and compile checks.

Prompt Template

You are a senior TypeScript engineer generating interfaces and related types only from the schema, samples, and constraints I supply. Treat sample JSON as incomplete evidence unless I confirm it is exhaustive. Resolve material ambiguity about optional, nullable, polymorphic, recursive, and open-ended fields before presenting the result as final.

Source: [JSON samples, JSON Schema, OpenAPI excerpt, database shape, existing code]
Source authority and completeness: [canonical schema, representative samples, partial example, unknown]
TypeScript version: [version]
Compiler options: [strict, exactOptionalPropertyTypes, noUncheckedIndexedAccess, other]
Runtime and consumer: [browser, Node.js, package API, React app, server response]
Root type name: [name]
Naming and export convention: [details]
Optional versus nullable rules: [details]
Date, timestamp, bigint, decimal, binary, ID, URL, and enum handling: [details]
Arrays, tuples, dictionaries, and additional properties: [details]
Union or discriminator rules: [details]
Readonly or mutability requirements: [details]
Existing shared types to reuse: [paste]
Runtime validation library or boundary: [none, Zod, Valibot, io-ts, other]
Code-generation constraints: [interfaces only, interfaces plus aliases, no enums, no any, other]
Representative valid and invalid payloads: [sanitized examples]

Provide:
1. An assumptions table listing verified facts, inferred choices, unresolved questions, and consequences.
2. Complete formatted TypeScript definitions with imports and exports where needed.
3. Interfaces for extensible object shapes and type aliases where unions, primitives, tuples, or mapped types are clearer; explain notable choices.
4. Explicit handling of absent, undefined, null, unknown, and additional fields without silently treating them as equivalent.
5. Safe date and numeric boundary guidance; do not label runtime strings as Date or unsafe numbers without a conversion plan.
6. A runtime-validation boundary when inputs are external, plus optional validator code only for the confirmed library and version.
7. Small valid and invalid examples tied to the supplied source rather than invented domain rules.
8. Compile-time assertions or a minimal type-check fixture covering required fields, nullability, unions, and nested arrays.
9. Commands to format and type-check using the project's verified package manager and scripts, or placeholders when unknown.
10. A final audit for any, unsafe assertions, duplicate types, wrong casing, optional-null confusion, lossy numbers, recursive loops, unmodeled variants, and invented fields.

Do not invent fields, enum members, format guarantees, package versions, successful compilation, or runtime validation. If samples conflict or do not establish a type safely, use unknown or a clearly labeled provisional union and ask for the authoritative schema.

Example Output

Assumptions

- The sample is representative, not exhaustive.

- status has only the two supplied values for now.

- createdAt arrives as an ISO-formatted string and is parsed at the application boundary.

- metadata is open-ended and must not use any.

Types

type UserStatus = "active" | "inactive";

interface UserResponse {

id: string;

status: UserStatus;

displayName?: string | null;

createdAt: string;

metadata: Record<string, unknown>;

}

Boundary Note

Validate external input before assigning UserResponse. Convert createdAt to Date only after successful format validation.

Checks

A fixture should reject a missing id, an unsupported status, a numeric createdAt, and metadata values accessed without narrowing.

Unresolved

Confirm whether displayName can be absent, null, or both, and whether additional status values are allowed before publishing the type.

Tips for Best Results

  • ๐Ÿ’กProvide a canonical schema whenever possible; one JSON sample cannot prove every optional field or union.
  • ๐Ÿ’กState strict compiler options because optional and indexed-access behavior changes the safe model.
  • ๐Ÿ’กPair static types with runtime validation whenever data crosses an external boundary.

Frequently Asked Questions

What is the TypeScript Interface Generator Prompt prompt?

Generate precise TypeScript interfaces and related types from sample data or a verified schema, with explicit nullability, unions, runtime-boundary notes, and compile checks. It's a free ChatGPT prompt template from our Coding collection โ€” copy it, fill in the bracketed variables, and paste it into your AI tool.

Which AI tools work with this prompt?

It's written and tested for ChatGPT, Claude and Gemini. Any AI assistant that accepts free-form text prompts will handle it well.

How do I customize this ChatGPT prompt?

Replace the bracketed variables โ€” such as [version], [name], [details] โ€” with your own details before running it. Provide a canonical schema whenever possible; one JSON sample cannot prove every optional field or union.

Is this prompt free to use?

Yes. Every prompt on PromptAtlas is free to copy, customize, and use โ€” no signup required.