I'm trying to return both errors and success from a function
type Result = ResultSuccess | ResultFailure;
interface ResultSuccess {
success: true,
response: Interface1
}
interface ResultFailure{
success: failure,
error: Interface2
}
This works fine, but then in my typescript code
// 'responses' is Result[]
const successfulRequests = responses.filter((x) => x.success).map((x) => x.response)
Here there's a type error because the x.response cannot determine if it's a success or failure (therefore would exist or not), despite checking for the type being 'success: true'
Help is appreciated.