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 silently — postPing: { 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.
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-tswith only the@hey-api/typescriptplugin 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:
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 silently —
postPing: { 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:
call<K extends keyof Operations>(id: K, data: Operations[K]['data'])This is specifically for types-only consumers — SDK-plugin users already get per-operation functions.
Reproducible example or configuration
System information (optional)
@hey-api/openapi-ts0.99.0, types-only, Node 26 / pnpm 11.