I have a base class called Parent
from a library with certain properties, and a derived class Child
which inherits the same properties but with different data types.
class Parent {
propertyA: string;
propertyB: string;
propertyC: string;
constructor() {
this.propertyC = '';
}
}
class Child extends Parent {
propertyA: number;
propertyB: number;
}
I'm attempting to change the data type of multiple properties in the parent class, but I am encountering an error ts(2416)
.
Type 'number' is not assignable to type 'string'.
I considered converting the Parent
class into an interface and utilizing Omit<>
to exclude propertyA
and propertyB
, however, since the class is located in a library, that approach is not feasible.
Due to the fact that the Child
class will be utilized to represent existing data (such as a table with the three properties) as a generic type for functions within the firebase library (specifically the
FirebaseFirestore.CollectionReference<T>
type), I cannot use composition (PropertyParent: Parent
as a Child
property) or rename the properties.
Are there alternative methods to achieve this?