My API handler returns a promise of a type
. The object returned can be one of the following interfaces, depending on the API response:
export interface Event {
statusCode: number
}
export interface CreateEvent extends Event {
data: Object
}
export interface Forbidden {
message: string
}
However, I am facing issues with the types during testing. The error message
this value doesn't exist on type:
indicates a missing value from Forbidden when it was supposed to be a successful response.
My expected types are:
type ApiResponse = Forbidden | Event | CreateEvent
or
export enum ApiResponse {CreateEvent, Forbidden, Event}
When I set the API function return type to:
callApi = (event: Event): Promise<ApiResponse> => {...}
I'm unsure about what ts
expects in this situation. It seems like a basic behavior, but I can't figure it out.