From b23f4f1fc5d39af1fa48c85868f47553b6e70f5b Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Wed, 3 Mar 2021 11:22:59 -0500 Subject: [PATCH] fix(index.d.ts): allow creating statics without passing generics to `Schema` constructor Fix #9969 --- index.d.ts | 2 +- test/typescript/models.ts | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 999fc7badb9..aa554d5166e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1052,7 +1052,7 @@ declare module 'mongoose' { type SchemaPreOptions = { document?: boolean, query?: boolean }; type SchemaPostOptions = { document?: boolean, query?: boolean }; - class Schema = Model, SchemaDefinitionType = undefined> extends events.EventEmitter { + class Schema = Model, SchemaDefinitionType = undefined> extends events.EventEmitter { /** * Create a new schema */ diff --git a/test/typescript/models.ts b/test/typescript/models.ts index c65402c7829..b6917f876e8 100644 --- a/test/typescript/models.ts +++ b/test/typescript/models.ts @@ -1,4 +1,4 @@ -import { Schema, Document, Model, connection } from 'mongoose'; +import { Schema, Document, Model, connection, model } from 'mongoose'; function conventionalSyntax(): void { interface ITest extends Document { @@ -49,6 +49,21 @@ function insertManyTest() { }); } +function schemaStaticsWithoutGenerics() { + const UserSchema = new Schema({}); + UserSchema.statics.static1 = function() { return ''; }; + + interface IUserDocument extends Document { + instanceField: string; + } + interface IUserModel extends Model { + static1: () => string; + } + + const UserModel: IUserModel = model('User', UserSchema); + UserModel.static1(); +} + const ExpiresSchema = new Schema({ ttl: { type: Date,