A tagged response shape lets code handle successful data and errors predictably.

API Response Case

response.ts
type ApiResponse =
    | { ok: true; value: number }
    | { ok: false; error: string };

function label(response: ApiResponse): string {
    if (response.ok) {
        return `value:${response.value}`;
    }

    return `error:${response.error}`;
}

const requestOk: boolean = ;
const response: ApiResponse = requestOk
    ? { ok: true, value: 42 }
    : { ok: false, error: "missing" };

console.log(label(response));
type ApiResponse =
    | { ok: true; value: number }
    | { ok: false; error: string };

function label(response: ApiResponse): string {
    if (response.ok) {
        return `value:${response.value}`;
    }

    return `error:${response.error}`;
}

const requestOk: boolean = ;
const response: ApiResponse = requestOk
    ? { ok: true, value: 42 }
    : { ok: false, error: "missing" };

console.log(label(response));
tagged response A discriminated response object keeps success and error handling in one explicit branch.