Here is the code snippet I am working with:
if (event.hasOwnProperty('body')) {
Context.request = JSON.parse(event.body) as T;
} else {
Context.request = event;
}
The variable event
is defined as follows:
private static event: aws.IGatewayEvent | ut.IGenericEvent;
The first type has a "body" attribute, while the second type does not. Despite this distinction, I assumed that my conditional statement would distinguish between the two types correctly and prevent Typescript from throwing the error:
Property 'body' does not exist on type 'IGenericEvent | IGatewayEvent'.