Replies: 2 comments
-
you could outsource methods to different files, but personally i dont recommend it class User {
@prop()
public username?: string;
public someInstanceMethod!: typeof someInstanceMethod;
}
User.prototype.someInstanceMethod = someInstanceMethod;
const UserModel = getModelForClass(User);
async function main() {
await mongoose.connect(`mongodb://localhost:27017/`, {
dbName: 'verifyMASTER',
});
const doc = new UserModel({ username: 'user1' });
doc.someInstanceMethod();
console.log(doc);
await mongoose.disconnect();
}
main();
function someInstanceMethod(this: DocumentType<User>) {
return 'hello';
} and aside from just using less spacing or splitting the class somehow, it is not really possible to reduce the size |
Beta Was this translation helpful? Give feedback.
0 replies
-
Okey, so for static methods schema is the same, right (or I need to assign static function differently)? What I should pass instead of this: DocumentType to static method or nothing at all (however how do I access static members then)? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I have a question that is not exactly related to typegoose, but still valid. Let's say I have User class with plenty of fields and methods. Class size is 700 lines. Most of the lines are taken by big static/not static methods. Is there any way to reduce class size? I cannot just refactor methods to make them smaller, 'cause they use complex aggregation pipelines that constructed based on incoming params. Can I somehow decouple this methods, move to separate file and add to class later? Yeap, I can create helper function and will have implementation and invoke it inside class method, but maybe there is a better approach to do it? I read about ts mixins, but it looks like shit and more about applying functionality that repeats across different classes.
Beta Was this translation helpful? Give feedback.
All reactions