I am trying to define an object that can either contain data or an error.
export type ActionResult = {
data: any;
} | {
error: any;
};
function test():ActionResult {
return {
data: 3
}
}
When trying to access result of the function I get:
const v = test();
v.data = 23; // Property 'data' does not exist on type 'ActionResult'. Property 'data' does not exist on type '{ error: any; }'
What's the correct way of accessing either 'data' or 'error'?