faint-whiteF
VAPI6mo ago
faint-white

Type Narrowing Vapi.Call vs CallBatchResponse

When I invoke vapi.calls.create it returns the following type:
export type CallsCreateResponse = Vapi.Call | Vapi.CallBatchResponse;

Since there are no shared props, Typescript can't narrow it automatically. So I have to do something like:

const isCall = (response: CallsCreateResponse): response is Vapi.Call => {
  return 'id' in response;
};


I’d rather avoid writing this manually. Am I missing a better way to handle this?
Was this page helpful?