My code consists of two classes: an abstract superclass and an inherited class.
export abstract class Entity<IEntityData> {
protected readonly _source: IEntityData; // TODO: replace with private
protected constructor(entityData: IEntityData) { this._source = entityData }
get source(): IEntityData { return this._source }
}
The inherited class is defined as follows:
import { Entity } from './entity/entity';
interface ITestData {
foo: string;
bar: number;
}
export class Test<IEntityData extends ITestData = ITestData>
extends Entity<IEntityData> {
constructor(testData: ITestData) {
super(testData);
}
get foo(): string { return this.source.foo }
get bar(): number { return this.source.bar }
}
However, during the build process, an error occurs that I can't seem to resolve. The error message states:
src/app/data/models/test.ts:13:11 - error TS2345: Argument of type 'ITestData' is not assignable to parameter of type 'IEntityData'.
'ITestData' is assignable to the constraint of type 'IEntityData', but 'IEntityData' could be instantiated with a different subtype of constraint 'ITestData'.
13 super(testData);