TypeScript Type Generator
Create the TypeScript types that are tedious to write by hand. Turn a list of values into a literal union derived from a const array, with a type guard for runtime checks; build an object type together with its Partial, Readonly, Pick and Omit variants; or define a discriminated union with an exhaustive switch that makes the compiler report every unhandled case.
- Runs in your browser
- No sign-up
- Free to use
How to use TypeScript Type Generator
- Choose union, object type or discriminated union.
- Enter the values, properties or variants.
- Tick the helper types and functions you want.
- Copy the TypeScript.
TypeScript Type Generator features
Literal unions
From a const array, so values exist at runtime too.
Type guards
isStatus(value) for checking unknown input.
Utility types
Partial, Readonly, Pick, Omit and keyof variants.
Discriminated unions
Variants tagged by a kind property.
Exhaustive switch
assertNever makes missing cases a compile error.
Checked names
Pick and Omit keys are verified against the properties.
When to use TypeScript Type Generator
- Modelling statuses, roles and other fixed sets of values.
- Creating request types for create and update endpoints.
- Modelling events, actions or shapes with different fields.
- Writing reducers that must handle every action type.
TypeScript Type Generator FAQ
Why derive a union from a const array?
A union type disappears at runtime, but dropdowns, validation and tests often need the list of values. Declaring the array with as const and deriving the type keeps one source of truth.
What is a discriminated union?
A union of object types that share a literal property, such as kind. Checking that property narrows the value to one variant, so TypeScript knows which fields exist.
What does assertNever do?
It accepts only the type never. If a new variant is added and the switch does not handle it, the value is no longer never and the build fails.
When do I use Pick and Omit?
Pick creates a smaller type with selected properties, for example a summary. Omit removes properties, for example the id that the server assigns when creating a record.
type or interface?
Both work for objects. Unions, mapped types and utility-type combinations need type aliases.
Is anything uploaded?
No. Everything runs in your browser.
Type aliases that do more
Type aliases in TypeScript can describe things that interfaces cannot: unions of literal values, combinations of other types and transformations of existing ones. They are the building blocks of well-typed applications, but some patterns take several lines of careful code each time. This generator writes three of the most useful patterns.
Literal unions model a fixed set of values, such as order statuses. Written directly as a type, they vanish at runtime. The recommended pattern declares the values in an array with as const and derives the type with (typeof VALUES)[number], so the same list drives both the type and runtime code. A generated type guard checks whether an unknown value is one of them, which is handy when reading query parameters or JSON.
Object types often come with variations. An update endpoint accepts some fields, which is Partial of the full type; a create form leaves out server-assigned fields, which is Omit; a list view needs a summary, which is Pick. Generating these from one base type keeps them in sync, and the generator checks that every key given to Pick or Omit really exists.
Discriminated unions model values that can take several forms with different fields: shapes, payment methods, API results or Redux actions. Each variant has a tag property with a literal value. Switching on the tag narrows the type, so each case can use its own fields safely.
The exhaustive check completes the pattern. In the default branch, assertNever receives the value, which TypeScript has narrowed to never if all variants are handled. When someone adds a variant later and forgets a case, the build fails at that switch.