Discriminated union AI response envelope on status.
status
Narrow on status to get type-safe access to data and error:
data
error
'success'
T
'error'
undefined
'partial'
Partial<T>
Provide type-safe AI result handling without casting.
function handle<T>(response: AiResponse<T>): T | undefined { if (response.status === 'success') { return response.data; // T } return undefined;} Copy
function handle<T>(response: AiResponse<T>): T | undefined { if (response.status === 'success') { return response.data; // T } return undefined;}
Discriminated union AI response envelope on
status.