Comments (11)
Hello. When Typegoose was created I wanted an explicit decoration flow. It would feel a bit odd that when you define a function it automatically becomes a static or instance method.
In my opinion explicitness is a bit better here since props must to be defined with decorators.
Also this gives room to create helping methods which are not part of the schema. (I can't think of a use case actually.) Also it could be done the other way around like defining an @ignore
decorator for methods.
I would stick with explicitness.
from typegoose.
Looks like all we need to do in typegoose is to register class fields. All virtual, instance and static methods can be collected by loadClass()
helper function:
http://mongoosejs.com/docs/advanced_schemas.html
from typegoose.
It would feel a bit odd that when you define a function it automatically becomes a static or instance method.
It would feel a bit odd that when you call the method of a model/document and you will get undefined is not a function
, because current types just do the &
with the class definition, so TS thinks that it have all methods and props from the class are available.
If you really need to exclude some methods, you can make this private
(so no public type available) and decorate with @privateMethod
.
from typegoose.
Yes, it should be handled automatically:
const staticPropNames = Object.getOwnPropertyNames(ClassType);
const instancePropNames = Object.getOwnPropertyNames(ClassType.prototype);
All you need to do it to filter lenght
, prototype
and name
from staticPropNames
and constructor
from instancePropNames
.
from typegoose.
@szokodiakos Thanks for your kind response. I see the point, but I assume that adding some magic at the cost of a one more layer of implicitness is something this library is expected to do. Defining schemas manually is also more explicit than inferring them from typescript metadata, but i prefer the latter, that's why I'm here.
On the other hand, explicitness can be understood as
doing what is expected to be done
and by extending the Typegoose
base class I clearly express my intention to use the class as a template for building a schema. I can hardly imagine a usecase when the possibility not to add a method to the schema would be required, while this method wouldn't be accessible from the scope of a model. I think, simple things should be done simply, leaving space to use some workarounds in more rare and complicated cases.
from typegoose.
The @prop
decorator is meaningful, while it can be used to configure props. On the contrary, @staticMethod
and @instanceMethod
only add some notional duplication.
from typegoose.
All right, the last argument bought me, however this will be a breaking change.
Currently theres a feature/4
branch which includes some breaking changes. I would like to release all these stuff together.
from typegoose.
wow I haven't heard about that utility function. This really removes the need of any decorator except the property ones.
from typegoose.
Mmh was this abandoned? I just ran into the same odd issue where I forgot a decorator, TypeScript was happy and then I got a missing method error at runtime :(
from typegoose.
Mmh was this abandoned?
All important comments on that:
#48 (comment)
currently its a "won't fix"
(and @szokodiakos has "left" the project, and so left the branch feature/4
, where it wasnt implemented, but i made in #356 a vote about continuing feature/4
for release 6)
from typegoose.
this is included / removed in v6.0.0
@Ben305 this can be closed
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.