I am looking for a way to define an interface in a child class that can be accessed by a method in the parent abstract class.
For instance, consider the following code snippet:
export default abstract class MyClass {
protected foo(arg: this.myInterface): any {
//
}
}
export default class FooClass extends MyClass {
protected myInterface: DataInterface;
}
In this example, the DataInterface
interface should be accessible through the foo
method in the MyClass
abstract class. Is this achievable? If not, what would be the alternative approach?
-- EDIT
Just to provide some context, the Abstract Class I am working with is named BaseService
, and I am planning on creating services that inherit from it.
These services will utilize multiple interfaces, and it is crucial for me to be able to access these interfaces from the BaseService
to ensure the correct data structure is being used.
The data structures I need to validate are related to attributes for a table in a SQL Server database, which means they could vary widely.
For example:
export interface IVehicleData {
vehicle_id?: number;
vehicle_name?: string;
vehicle_created_at?: Date;
vehicle_updated_at?: Date;
}
In different classes, I might have different interfaces with unique attributes. Additionally, there could be several interfaces utilized, not restricted to just one.