---
name: typescript-interface-generator
description: "Turns a plain-language data model into precise TypeScript interfaces or types with the right optional fields, JSDoc, and optional Zod or JSON Schema counterparts, so the shape is written once and stays in sync. Use when a data model exists only as a verbal or written description and needs turning into TypeScript interfaces or types with optional fields and unions decided. Do not use for inferring types from a JSON sample, documenting types that already exist, or refactoring existing type definitions. Related topics: coding, typescript, interface."
---

# TypeScript Interface Generator

Turns a plain-language data model into precise TypeScript interfaces or types with the right optional fields, JSDoc, and optional Zod or JSON Schema counterparts, so the shape is written once and stays in sync.

## When to use

Use this skill when a data model exists only as a verbal or written description and needs turning into TypeScript interfaces or types with optional fields and unions decided. Do not use it for inferring types from a JSON sample, documenting types that already exist, or refactoring existing type definitions.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Translate each described field into a type, turning enumerated values into literal unions and dates into a stated representation.
3. Mark optional only the fields the description says can be missing, and record each assumption where it was ambiguous.
4. Choose interface or type per the request and extend the base interface without redeclaring its fields.
5. Add the requested extras (JSDoc, example object, Zod or JSON Schema, utility variants) derived from the same field model.
6. Check the example object compiles against the type and the schema accepts it, then list the assumptions.

## Inputs

- **Name of the interface or type** (free text, e.g. "UserProfile")
- **What the data represents and its fields** (longer free text)
- **Optional fields** (longer free text)
- **Declare with** (choose one: interface, type, Both with a note on when to use each)
- **Extends an existing interface** (choose one: Yes, No)
- **Name of the extended interface** (free text, e.g. "BaseEntity")
- **Extra features** (choose any: JSDoc comments, Example instantiation, Zod schema, JSON Schema, Utility type variants such as Partial and Readonly)

## Output

A single TypeScript code block containing the type definitions and requested extras, followed by a bulleted list of assumptions.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### TypeScript Interface Generator

Write the TypeScript types for the data model described below.

- Name of the interface or type: {{Name of the interface or type}}
- What the data represents and its fields: {{What the data represents and its fields}}
- Optional fields: {{Optional fields}}
- Declare with: {{Declare with}}
- Extends an existing interface: {{Extends an existing interface}}
- Name of the extended interface: {{Name of the extended interface}}
- Extra features: {{Extra features}}

Model the data before writing syntax. Turn every "one of" into a string literal union rather than string, every id into a branded or at least named alias, and every date into a stated representation (Date or ISO string) since the description rarely says. Mark a field optional only when the description says it can be missing; a field that is always present but sometimes empty is not optional. Prefer interface for object shapes that may be extended and type for unions and intersections, and say so when asked for both. When extending, inherit the base fields and only declare the new ones.

Add JSDoc on each field when requested, using the meaning from the description rather than restating the name. Generate the Zod schema or JSON Schema from the same model so the two cannot drift, and show one example object that satisfies the type. Add utility type variants only where they have a clear use, such as a CreateInput that omits server-generated fields.

### Output
Return one TypeScript code block with the interface or type and the requested extras, followed by a short list of assumptions made where the description was ambiguous.

## Pitfalls

- Typing an enumerated field as string, which throws away the only compile-time check the model offers.
- Marking fields optional because they are sometimes empty, so every consumer has to null-check a value that is always present.
- Writing the Zod schema by hand after the interface, so the two drift the first time either is edited.
