Here is a defined schema for an account
class AccountSchema;
Below is the model declaration for the account
const AccountClass: Model<AccountSchema & Document>;
class Account extends AccountClass;
Why isn't this functioning as expected?
type ExtractSchema<T extends Model<Document>> = T extends Model<infer D & Document> ? D : never;
class Service<T extends Model<ExtractSchema<T> & Document>> {
public async getSchema(): ExtractSchema<T>;
}
class AccountService extends Service<typeof Account> {
public test() {
[ERROR: this.getSchema() returns never]
this.getSchema()
}
}
What is the most effective approach to extract the schema using generics without involving Javascript getter and setter functions, but only plain fields?