In the code snippet below, you can see a logging method:
private logData<T, S>(operation: string, responseData: T, requestData?: S) {
this.logger.log(operation + ' ' + this.url);
if (requestData) {
this.logger.log('SENT');
this.logger.log(requestData);
}
this.logger.log('RECEIVED');
this.logger.log(responseData);
return responseData;
}
The requestData
parameter is optional. The aim is to call logData
without specifying the S
type when requestData
is not sent with the method. For instance, instead of using
this.logData<T, any>('GET', data)
, I would like to use this.logData<T>('GET', data)
.
Is there a way to accomplish this?