Comments (8)
@szokodiakos any solution to this problem
from typegoose.
Thanks for your interest in Typegoose. Plugins are currently not supported however can be easily implemented (which I will try to do in sometime in the near future) as class decorators.
I will change this to enhancement and create a pull request for this when ready.
If I am correct your other question is that is it possible to reuse properties? I haven't tested this but if you create a base class 'A' which extends Typegoose and you extend class 'B' and 'C' from class 'A' then B and C will have A's properties. Is this what you want to do?
from typegoose.
Hey @stuartkuentzel, thanks for your interest in Typegoose!
Unfortunately when applying a Mongoose plugin, TypeScript has no information about the plugins "class signature" e.g. which new properties and methods will the plugin add to the schema. This is why the additional typing infos must be provided by hand, as the Typegoose docs states:
If the plugin enhances the schema with additional properties or instance / static methods this typing information should be added manually to the Typegoose class as well.
So in your case you must add authenticate
, serializeUser
, and deserializeUser
to the Typegoose extending User class.
import * as passportLocalMongoose from 'passport-local-mongoose';
import { prop, Typegoose, plugin } from 'typegoose';
@plugin(passportLocalMongoose)
class User extends Typegoose {
@prop()
email: string;
@prop()
username: string;
@prop()
password: string;
// method return values are not represented here, you'll have to look for the plugin's docs to see what they actually return
static authenticate();
static serializeUser();
static deserializeUser();
}
export const UserModel = new User().getModelForClass(User);
And basically that is it! Hope it helps.
I am going to attach this link to stackoverflow too.
from typegoose.
Thanks for the plugin annotation works great!
For some plugins like mongoose-pagination it would be great to initialize static as an empty object.
Currently you must add one static methods to the schema so it can initialize it correctly.
The extension of classes seems not possible at the moment.
The extended classes do not inherit the attributes from the parent class also not the pre decorators.
Don't know if they inherit the static methods.
from typegoose.
Hey, awesome work on Typegoose. I'm having issues using the plugin functionality. Tried to implement it using the docs, but can't seem to get it to work. https://stackoverflow.com/questions/45775134/using-plugins-with-typegoose.
from typegoose.
The issue I'm having is, TypeScript doesn't like if I follow with an instanceMethod. If I follow anything after, for example static authenticate(): any;
, the following instance method will say "function implementation name must be authenticate". Thanks for your help!
from typegoose.
@stuartkuentzel okay i will try to reproduce the problem, meanwhile can you attach what TypeScript / Node / NPM versions are you using?
Thanks!
from typegoose.
@szokodiakos Sure, I'm using Node 8.2.1, TypeScript 2.4.2, and NPM 5.3.0.
from typegoose.
Related Issues (20)
- Please use the new Repository to open new issues HOT 4
- Pre hook supplied function error HOT 56
- TypeError: Class constructor Typegoose cannot be invoked without 'new' HOT 1
- [Request] Setting Collection Name and other Schema options via annotation and reflections
- [Question] Import ObjectId from Typegoose? HOT 4
- Please archive this repo
- Is there any way to achieve schema inheritance with typegoose? HOT 2
- [Question] Type of User.x property is not a y HOT 1
- Is it possible to use getModelForClass with generics? HOT 1
- [Question] HOT 1
- my populate field cant be queried out HOT 3
- [Question] HOT 1
- [Question] Problems reusing the same schema for both collection and subdocument HOT 1
- [Question] Can we add custom error messages when @prop options fail? HOT 2
- [Question] Are transactions supported for deleteMany? HOT 1
- [Question] Possible to have Query type support? HOT 1
- bi-directional virtuals population issue HOT 1
- Cannot use same model on two connections. HOT 2
- [Question] Is there a `required if` feature on model classes? HOT 2
- Both updatedBy and CreatedBy are getting updated after update operation on model object HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typegoose.