Skip to main content

Type Alias: AiResponse<T>

AiResponse<T> = { data: T; metadata: AiResponseMetadata; status: "success"; } | { data: undefined; error: AiResponseError; metadata: AiResponseMetadata; status: "error"; } | { data: Partial<T>; error?: AiResponseError; metadata: AiResponseMetadata; status: "partial"; }

Defined in: src/ai/types.ts:84

Discriminated union AI response envelope on status.

Type Parameters​

T​

T

Remarks​

Narrow on status to get type-safe access to data and error:

  • 'success' — data is T, no error
  • 'error' — data is undefined, error is populated
  • 'partial' — data is Partial<T>, optional error

Intent​

Provide type-safe AI result handling without casting.

Example​

function handle<T>(response: AiResponse<T>): T | undefined {
if (response.status === 'success') {
return response.data; // T
}
return undefined;
}