In my Angular 9 application, I have two classes that I am using as services: class A and class B, where class B extends class A.
class A{
exportToCSV(data: any[], headers: any[]){
....
}
}
class B extends A{
exportToCSV(data: any[], headers: any[], metadata : any){
....
}
}
An error is being thrown:
Property 'exportToCSV' in type 'B' is not assignable to the same property in base type 'A'. Type '(data: any[], headers: any[], metadata : any) => void' is not assignable to type '(data: any[], headers: any[]) => void'.ts(2416)
According to the documentation provided at https://www.typescriptlang.org/docs/handbook/classes.html
this should work, but it doesn't. Making the metadata optional however, makes it work (https://medium.com/@kevinkreuzer/typescript-method-overloading-c256dd63245a).
I am attempting to override the method, but it seems to be overloading instead. Can someone clarify why this is happening?