Skip to main content
The @hey-api/typescript plugin is the foundation of OpenAPI TypeScript. It generates TypeScript types and interfaces from your OpenAPI specification, providing full type safety for your API.

Installation

The TypeScript plugin is included by default when you install @hey-api/openapi-ts:

Configuration

Add the plugin to your openapi-ts.config.ts:

What It Generates

The TypeScript plugin generates a types.gen.ts file containing:
  • Schema types - TypeScript types for all schema definitions
  • Request types - Types for request bodies, query parameters, and headers
  • Response types - Types for response bodies and status codes
  • Error types - Types for error responses
  • Enum types - JavaScript objects, TypeScript enums, or union types

Configuration Options

case

Casing convention for generated type names.
string
default:"PascalCase"
Options: 'PascalCase', 'camelCase', 'snake_case', 'kebab-case'

enums

Control how enums are generated. By default, enums are emitted as TypeScript union types to preserve runtime-free output.
boolean | string | object
default:"false"
Generate enums as JavaScript objects, TypeScript enums, or const enums.

topType

The top type to use for untyped or unspecified schema values.
'unknown' | 'any'
default:"'unknown'"
  • 'unknown' - Safe top type, requires type narrowing before use
  • 'any' - Disables type checking, can be used anywhere

definitions

Customize naming for reusable schema definitions.
string | function | object
default:"'{{name}}'"
Controls generation of shared types that can be referenced across requests and responses.

requests

Customize naming for request-specific types (body, query, path parameters, headers).
string | function | object
default:"'{{name}}Data'"
Controls generation of types for request bodies, query parameters, path parameters, and headers.

responses

Customize naming for response-specific types.
string | function | object
default:"'{{name}}Responses'"
Controls generation of types for response bodies and status codes.

errors

Customize naming for error-specific types.
string | function | object
default:"'{{name}}Errors'"
Controls generation of types for error response bodies and status codes.

webhooks

Customize naming for webhook-specific types.
string | function | object
default:"'{{name}}WebhookRequest'"
Controls generation of types for webhook payloads and webhook requests.

Common Patterns

Custom Naming Convention

Generate JavaScript Enums

Custom Type Transformer

Plugin Hooks

The TypeScript plugin supports lifecycle hooks for advanced customization:
function
Called after the plugin generates types. Useful for post-processing.
function
Called before the plugin generates types. Useful for pre-processing.

Next Steps

SDK Plugin

Generate type-safe SDK functions for your API operations.

Schemas Plugin

Generate runtime JSON schemas for validation.

Transformers Plugin

Transform response data at runtime.

HTTP Clients

Choose an HTTP client for making requests.