mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
adds ability to define dynamic static methods on model instances fixes #5193
This commit is contained in:
@@ -133,6 +133,10 @@ conn1.openSet('mongodb://localhost/test', 'db', {
|
||||
conn1.close().catch(function (err) {});
|
||||
conn1.collection('name').$format(999);
|
||||
conn1.model('myModel', new mongoose.Schema({}), 'myCol').find();
|
||||
interface IStatics {
|
||||
staticMethod1: (a: number) => string;
|
||||
}
|
||||
conn1.model<{}, IStatics>('').staticMethod1;
|
||||
conn1.modelNames()[0].toLowerCase();
|
||||
conn1.config.hasOwnProperty('');
|
||||
conn1.db.bufferMaxEntries;
|
||||
@@ -1338,4 +1342,14 @@ LocModel.findOneAndUpdate().exec().then(function (arg) { arg.openingTimes; });
|
||||
LocModel.geoSearch({}, {
|
||||
near: [1, 2],
|
||||
maxDistance: 22
|
||||
}, function (err, res) { res[0].openingTimes; });
|
||||
}, function (err, res) { res[0].openingTimes; });
|
||||
interface IStatics {
|
||||
staticMethod2: (a: number) => string;
|
||||
}
|
||||
var StaticModel = mongoose.model<Location, IStatics>('Location');
|
||||
StaticModel.staticMethod2(9).toUpperCase();
|
||||
(new StaticModel()).save(function (err, doc) {
|
||||
doc.openingTimes;
|
||||
doc.model<Location, IStatics>('').staticMethod2;
|
||||
});
|
||||
StaticModel.model<Location, IStatics>('').staticMethod2;
|
||||
9
mongoose/mongoose.d.ts
vendored
9
mongoose/mongoose.d.ts
vendored
@@ -225,6 +225,8 @@ declare module "mongoose" {
|
||||
*/
|
||||
static model<T>(name: string, schema?: _mongoose.Schema, collection?: string,
|
||||
skipInit?: boolean): _mongoose.ModelConstructor<T>;
|
||||
static model<T, Statics>(name: string, schema?: _mongoose.Schema, collection?: string,
|
||||
skipInit?: boolean): Statics & _mongoose.ModelConstructor<T>;
|
||||
|
||||
/**
|
||||
* Returns an array of model names created on this instance of Mongoose.
|
||||
@@ -448,6 +450,7 @@ declare module "mongoose" {
|
||||
* @returns The compiled model
|
||||
*/
|
||||
model<T>(name: string, schema?: Schema, collection?: string): ModelConstructor<T>;
|
||||
model<T, Statics>(name: string, schema?: Schema, collection?: string): Statics & ModelConstructor<T>;
|
||||
|
||||
/** Returns an array of model names created on this connection. */
|
||||
modelNames(): string[];
|
||||
@@ -2211,7 +2214,8 @@ declare module "mongoose" {
|
||||
findById(id: Object | string | number, projection: Object, options: Object,
|
||||
callback?: (err: any, res: Model<T>) => void): ModelQuery<Model<T>, T>;
|
||||
|
||||
model<U>(name: string): ModelConstructor<U>;
|
||||
model<T>(name: string): ModelConstructor<T>;
|
||||
model<T, Statics>(name: string): Statics & ModelConstructor<T>;
|
||||
|
||||
/**
|
||||
* Creates a Query and specifies a $where condition.
|
||||
@@ -2442,7 +2446,8 @@ declare module "mongoose" {
|
||||
* Returns another Model instance.
|
||||
* @param name model name
|
||||
*/
|
||||
model<U>(name: string): ModelConstructor<U>;
|
||||
model<T>(name: string): ModelConstructor<T>;
|
||||
model<T, Statics>(name: string): Statics & ModelConstructor<T>;
|
||||
|
||||
/**
|
||||
* Removes this document from the db.
|
||||
|
||||
Reference in New Issue
Block a user