I necessarily need to implement arrow functions in this implementation and I need to convert the input from AWS into a custom model in order to avoid doing the same logic for each APIs. I thought of using decorators to do this each function. As it's considered as a property by the compiler it won't find the descriptor property and throw exceptions. Is there a workaround to trick the compiler to recognise the arrow function as an actual function and pass the descriptor?
@API(EndpointType.POST)
public login = async (event: Input): Promise<APIGatewayProxyResult> => {
... logic
}
export function API(apiType:EndpointType): any {
return (target: any, propertyKey: string, descriptor?: TypedPropertyDescriptor<any>) => {
descriptor.value = function(request) {
... logic
const bindedOriginalFunction = originalFunction.bind(this)
const result = bindedOriginalFunction(finalResult);
return result
}
return descriptor;
}
Does it have to be an arrow function?
Arrow function in your case is not a method (function owned by the object). You have a property that hold a function (arrow function) that is owned someone else.