Reputation: 813
I have a problem with generic types. its simplified version is as this.
import { Document, Model } from 'mongoose';
interface Base {
age: number;
}
class Test<T extends Base> {
private t: Model<T & Document>
}
i get an error for this part Model<T & Document>
which says this:
Type 'T & Document<any, {}>' does not satisfy the constraint 'Document<any, {}>'
Does anyone has any idea?
Upvotes: 0
Views: 203
Reputation: 1059
That because the type of Document
is class Document<...>, that is why you can't use intersecion type &
with the "Object" type directly.
To solve this issue, you could use extends
to extend the class like following:
class Base extends Document {
age?: number;
}
class Test<T extends Base> {
private t?: Model<T>;
}
Upvotes: 1