I have created this class that works with generics in TypeScript
export class ModelTransformer {
static hostelTransformer: HostelTransformer;
static fromAtoB(instance: T): U {
if (instance instanceof HostelType) {
return ModelTransformer.hostelTransformer.fromAtoB (instancet);
}
}
}
But when I compile it I have those compilation errors:
src/model/transformer/model.transformer.ts:11:47 - error TS2304: Cannot find name 'T'.
11 static fromAtoB(instance: T): U {
src/model/transformer/model.transformer.ts:11:51 - error TS2304: Cannot find name 'U'.
11 static fromAtoB(instance: T): U {
I have tried the solution proposed, but then I have this error:
error TS2366: Function lacks ending return statement and return type does not include 'undefined'.
U | void, for example, since it doesn't return anything in case instance is not instanceof HostelType.