Kevin Jump
04/19/2024, 8:44 AMts
class TestModelBase {
colour?: string;
};
class SizeModel extends TestModelBase
{
size?: number;
}
export class TestServiceBase<TObject extends TestModelBase> {
model? : TObject;
getColor() {
return this.model?.colour;
}
}
export class TestSizeService extends TestServiceBase<SizeModel> {
// override
getColor(): string | undefined {
return this.model?.colour;
}
getSize() : number | undefined {
return this.model?.size;
}
}
What i am aiming for in my code is a base "context" that will have some core functionality in it, including going off to the server to get things (via a repoisitory that i can then extend and pass in another 'repository' (of same basemodel type) that calls different server end points but gets the 'same' result types just for different things.
any red flags, have i missed something in this pattern ?Ravi
04/19/2024, 3:07 PMKevin Jump
04/19/2024, 3:14 PMKevin Jump
04/19/2024, 3:15 PMmodel?
* with the question mark *is implicitly TObject | undefined
which is why the returns on those methods become valie | undefined.