Currently, I am involved in a project that is based on classes and I have my primary class which I usually extend to other files because the implementation remains quite similar.
Here's one of the functions in the BaseSummaryManager
Page Object file:
protected handleGetSummary(summary: SummaryResponse) {
return {
account_number: summary.AccountNumber,
first_name: summary.FirstName,
last_name: summary.LastName,
email: summary.Email.trim().toLowerCase(),
};
}
The challenge I'm encountering is that in a specific service that extends BaseSummaryManager
, I need to return a different object structure as follows:
return {
account_number: summary.Data.AccountNumber,
first_name: summary.Data.FirstName,
last_name: summary.Data.LastName,
email: summary.Data.Email.trim().toLowerCase(),
};
Do you notice the presence of .Data which was not part of the original implementation?
To address this scenario, I have created an override function like this:
protected override handleGetSummary(summary: CustomSummaryResponse) {
return {
account_number: summary.Data.AccountNumber,
first_name: summary.Data.FirstName,
last_name: summary.Data.LastName,
email: summary.Data.Email.trim().toLowerCase(),
};
}
This makes use of CustomSummaryResponse
which includes the Data
object.
The issue I'm facing is that TypeScript does not permit me to change the parameter type in my service implementation. The error message reads:
Property 'handleGetSummary' in type 'CustomSummaryResponse' is not assignable to the same property in base type 'BaseSummaryManager'.
Type '(summary: CustomSummaryResponse) => { account_number: string; first_name: string; last_name: string; email: string; }' is not assignable to type '(summary: SummaryResponse) => { account_number: string; first_name: string; last_name: string; email: string; }'.
Types of parameters 'summary' and 'summary' are incompatible.
Type 'CustomSummaryResponse' is missing the following properties from type 'SummaryResponse': AccountNumber, FullName, FirstName, LastName, and 11 more.
Could you please guide me on how to correctly override this parameter in such a situation?