---
name: typescript-type-architect
description: "Derives a complete, accurate set of TypeScript types from a JSON or object sample: nested shapes get their own named types, repeated string values become unions, and nothing is left as any. Use when you have a JSON payload or object sample and need full TypeScript types for it, with nested shapes named and repeated values turned into unions. Do not use for types described in prose rather than data, or validating data at runtime against a type. Related topics: coding, typescript."
---

# TypeScript Type Architect

Derives a complete, accurate set of TypeScript types from a JSON or object sample: nested shapes get their own named types, repeated string values become unions, and nothing is left as any.

## When to use

Use this skill when you have a JSON payload or object sample and need full TypeScript types for it, with nested shapes named and repeated values turned into unions. Do not use it for types described in prose rather than data, or validating data at runtime against a type.

## 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. Scan every record in the sample and list each field with the set of value kinds observed, including null and missing.
3. Name a type for every nested object and infer array element types from all elements, so no shape is inlined or guessed from one item.
4. Convert repeated string values into literal unions or enums as requested, listing the values actually seen.
5. Apply the strictness mode: optional fields and unknown in strict, widened strings and index signatures in relaxed.
6. Order the output root type first, add JSDoc where the sample shows meaning, and list the inference decisions the sample could not settle.

## Inputs

- **Data sample** (longer free text)
- **Root type name** (free text, e.g. "Order")
- **Export style** (choose one: named export, default export)
- **Include JSDoc comments** (choose one: Yes, No)
- **Strictness** (choose one: strict, relaxed)
- **Also generate** (choose any: enums, union types, intersection types, literal types)

## Output

A single typescript code block with the root type, auxiliary types, and exports in the chosen style, then a bulleted list of ambiguous inference decisions.

## Prompt template

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

### TypeScript Type Architect

Derive TypeScript types from the data sample below.

- Data sample: {{Data sample}}
- Root type name: {{Root type name}}
- Export style: {{Export style}}
- Include JSDoc comments: {{Include JSDoc comments}}
- Strictness: {{Strictness}}
- Also generate: {{Also generate}}

Read the whole sample before naming anything. Give every nested object its own named type (OrderItem, ShippingAddress) rather than inlining, so the types can be reused and extended. Infer array element types from every element, not the first: a mixed array becomes a union. When a string field repeats a small set of values across records, make it a literal union or an enum as requested, and say which values were seen. Treat null as nullable, not as the type. In strict mode, a field missing from some records is optional and unknown values stay unknown; in relaxed mode, widen literal unions to string and allow index signatures where keys vary.

Name types in PascalCase from the field name, singularised for arrays. Add JSDoc only where the sample shows meaning (units, formats, example values). State any guess the sample cannot settle, such as whether a numeric string is really a number.

### Output
Return one code block tagged typescript with the root type first, the auxiliary types after it, and the export statements in the chosen style, followed by a short list of inference decisions that the sample left ambiguous.

## Pitfalls

- Inferring an array's element type from its first item, so a later record with a different shape fails to compile.
- Typing a nullable field as null because the only sample value was null, which hides the real type entirely.
- Turning a free-text field into a literal union because two records happened to share a value.
