Skip to content

feat(typescript): export an operationId-keyed Operations index type for types-only consumers #4319

Description

@kdumontnu

Description

Split out of #4316 (its "Ask 2") so each request can be tracked and reviewed on its own.

Context is the same as #4316: we use @hey-api/openapi-ts with only the @hey-api/typescript plugin and our own HTTP client. The generated per-operation types (PostPingData, PostPingResponses, …) are exactly what we build on, but there is no generated way to enumerate them.

Ask: export a single type keyed by operation ID that references each operation's types:

export type Operations = {
    postPing: { data: PostPingData; responses: PostPingResponses; errors: PostPingErrors };
    // …
};

Why it's needed

Today a types-only consumer who wants a generic typed wrapper has to hand-maintain the map above. The compiler catches stale names and missing entries, but pairing a key with a different operation's types compiles silentlypostPing: { data: GetPingData } is a valid object type. That miswiring only surfaces at runtime.

A generated index is correct by construction and stays in sync as the spec evolves. It enables:

  • one generic call site with full per-endpoint inference: call<K extends keyof Operations>(id: K, data: Operations[K]['data'])
  • exhaustive mapped types over all operations (handler tables, mock registries) that fail to compile when the spec adds an operation

This is specifically for types-only consumers — SDK-plugin users already get per-operation functions.

Reproducible example or configuration

export default defineConfig({
    input: './openapi.json',
    output: './src/generated',
    plugins: ['@hey-api/typescript'],
});

System information (optional)

@hey-api/openapi-ts 0.99.0, types-only, Node 26 / pnpm 11.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions