Skip to content

Commit 279c5eb

Browse files
committed
WIP: clean up most remaining errors re: #14954
1 parent b1215a8 commit 279c5eb

File tree

5 files changed

+71
-71
lines changed

5 files changed

+71
-71
lines changed

test/types/document.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ async function gh11960() {
243243
{},
244244
{},
245245
DefaultSchemaOptions,
246-
Parent,
247246
ParentDocument
248247
>({
249248
username: { type: String },

test/types/queries.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ async function gh12342_manual() {
437437
};
438438

439439
// 2nd param to `model()` is the Model class to return.
440-
const ProjectModel = model<Project, ProjectModelType>('Project', schema);
440+
const ProjectModel = model<Project, ProjectModelType>('Project', ProjectSchema);
441441

442442
expectType<HydratedDocument<Project>[]>(
443443
await ProjectModel.findOne().where('stars').gt(1000).byName('mongoose')

test/types/schema.test.ts

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ interface Actor {
4040
age: number
4141
}
4242
const actorSchema =
43-
new Schema<Actor & Document, Model<Actor & Document>, Actor>({ name: { type: String }, age: { type: Number } });
43+
new Schema<unknown, Actor & Document, Model<Actor & Document>, Actor>({ name: { type: String }, age: { type: Number } });
4444

4545
interface Movie {
4646
title?: string,
@@ -52,7 +52,7 @@ interface Movie {
5252
actors: Actor[]
5353
}
5454

55-
const movieSchema = new Schema<Document & Movie, Model<Document & Movie>>({
55+
const movieSchema = new Schema<unknown, Document & Movie, Model<Document & Movie>>({
5656
title: {
5757
type: String,
5858
index: 'text'
@@ -122,7 +122,7 @@ interface IProfile {
122122
age: number;
123123
}
124124
const ProfileSchemaDef: SchemaDefinition<IProfile> = { age: Number };
125-
export const ProfileSchema = new Schema<IProfile, Model<IProfile>>(ProfileSchemaDef);
125+
export const ProfileSchema = new Schema<unknown, IProfile, Model<IProfile>>(ProfileSchemaDef);
126126

127127
interface IUser {
128128
email: string;
@@ -133,7 +133,7 @@ const ProfileSchemaDef2: SchemaDefinition<IProfile> = {
133133
age: Schema.Types.Number
134134
};
135135

136-
const ProfileSchema2: Schema<IProfile, Model<IProfile>> = new Schema<IProfile>(ProfileSchemaDef2);
136+
const ProfileSchema2 = new Schema<unknown, IProfile, Model<IProfile>>(ProfileSchemaDef2);
137137

138138
const UserSchemaDef: SchemaDefinition<IUser> = {
139139
email: String,
@@ -178,27 +178,27 @@ function gh10287() {
178178
testProp: string;
179179
}
180180

181-
const subSchema = new Schema<Document & SubSchema, Model<Document & SubSchema>, SubSchema>({
181+
const subSchema = new Schema<unknown, Document & SubSchema, Model<Document & SubSchema>, SubSchema>({
182182
testProp: Schema.Types.String
183183
});
184184

185185
interface MainSchema {
186186
subProp: SubSchema
187187
}
188188

189-
const mainSchema1 = new Schema<Document & MainSchema, Model<Document & MainSchema>, MainSchema>({
189+
const mainSchema1 = new Schema<unknown, Document & MainSchema, Model<Document & MainSchema>, MainSchema>({
190190
subProp: subSchema
191191
});
192192

193-
const mainSchema2 = new Schema<Document & MainSchema, Model<Document & MainSchema>, MainSchema>({
193+
const mainSchema2 = new Schema<unknown, Document & MainSchema, Model<Document & MainSchema>, MainSchema>({
194194
subProp: {
195195
type: subSchema
196196
}
197197
});
198198
}
199199

200200
function gh10370() {
201-
const movieSchema = new Schema<Document & Movie, Model<Document & Movie>, Movie>({
201+
const movieSchema = new Schema<unknown, Document & Movie, Model<Document & Movie>, Movie>({
202202
actors: {
203203
type: [actorSchema]
204204
}
@@ -209,7 +209,7 @@ function gh10409() {
209209
interface Something {
210210
field: Date;
211211
}
212-
const someSchema = new Schema<Something, Model<Something>, Something>({
212+
const someSchema = new Schema<unknown, Something, Model<Something>, Something>({
213213
field: { type: Date }
214214
});
215215
}
@@ -221,7 +221,7 @@ function gh10605() {
221221
value: number
222222
};
223223
}
224-
const schema = new Schema<ITest>({
224+
const schema = new Schema<unknown, ITest>({
225225
arrayField: [String],
226226
object: {
227227
type: {
@@ -238,7 +238,7 @@ function gh10605_2() {
238238
someObject: Array<{ id: string }>
239239
}
240240

241-
const testSchema = new Schema<ITestSchema>({
241+
const testSchema = new Schema<unknown, ITestSchema>({
242242
someObject: { type: [{ id: String }] }
243243
});
244244
}
@@ -248,7 +248,7 @@ function gh10731() {
248248
keywords: string[];
249249
}
250250

251-
const productSchema = new Schema<IProduct>({
251+
const productSchema = new Schema<unknown, IProduct>({
252252
keywords: {
253253
type: [
254254
{
@@ -275,7 +275,7 @@ function gh10789() {
275275
addresses: IAddress[];
276276
}
277277

278-
const addressSchema = new Schema<IAddress>({
278+
const addressSchema = new Schema<unknown, IAddress>({
279279
city: {
280280
type: String,
281281
required: true
@@ -290,7 +290,7 @@ function gh10789() {
290290
}
291291
});
292292

293-
const userSchema = new Schema<IUser>({
293+
const userSchema = new Schema<unknown, IUser>({
294294
name: {
295295
type: String,
296296
required: true
@@ -312,7 +312,7 @@ function gh11439() {
312312
collection: string
313313
};
314314

315-
const bookSchema = new Schema<Book>({
315+
const bookSchema = new Schema<unknown, Book>({
316316
collection: String
317317
}, {
318318
suppressReservedKeysWarning: true
@@ -325,7 +325,7 @@ function gh11448() {
325325
age: number;
326326
}
327327

328-
const userSchema = new Schema<IUser>({ name: String, age: Number });
328+
const userSchema = new Schema<unknown, IUser>({ name: String, age: Number });
329329

330330
userSchema.pick<Pick<IUser, 'age'>>(['age']);
331331
}
@@ -335,7 +335,7 @@ function gh11435(): void {
335335
ids: Types.Array<Types.ObjectId>;
336336
}
337337

338-
const schema = new Schema<User>({
338+
const schema = new Schema<unknown, User>({
339339
ids: {
340340
type: [{ type: Schema.Types.ObjectId, ref: 'Something' }],
341341
default: []
@@ -355,7 +355,7 @@ function gh10900(): void {
355355
menuStatus: TMenuStatus;
356356
}
357357

358-
const patientSchema = new Schema<IUserProp>({
358+
const patientSchema = new Schema<unknown, IUserProp>({
359359
menuStatus: { type: Schema.Types.Mixed, default: {} }
360360
});
361361
}
@@ -578,8 +578,8 @@ export type AutoTypedSchemaType = {
578578
};
579579

580580
// discriminator
581-
const eventSchema = new Schema<{ message: string }>({ message: String }, { discriminatorKey: 'kind' });
582-
const batchSchema = new Schema<{ name: string }>({ name: String }, { discriminatorKey: 'kind' });
581+
const eventSchema = new Schema<unknown, { message: string }>({ message: String }, { discriminatorKey: 'kind' });
582+
const batchSchema = new Schema<unknown, { name: string }>({ name: String }, { discriminatorKey: 'kind' });
583583
batchSchema.discriminator('event', eventSchema);
584584

585585
// discriminator statics
@@ -594,11 +594,11 @@ batchSchema2.discriminator('event', eventSchema2);
594594

595595
function encryptionType() {
596596
const keyId = new BSON.UUID();
597-
expectError<Schema>(new Schema({ name: { type: String, encrypt: { keyId } } }, { encryptionType: 'newFakeEncryptionType' }));
598-
expectError<Schema>(new Schema({ name: { type: String, encrypt: { keyId } } }, { encryptionType: 1 }));
597+
expectError(new Schema<unknown>({ name: { type: String, encrypt: { keyId } } }, { encryptionType: 'newFakeEncryptionType' }));
598+
expectError(new Schema<unknown>({ name: { type: String, encrypt: { keyId } } }, { encryptionType: 1 }));
599599

600-
expectType<Schema>(new Schema({ name: { type: String, encrypt: { keyId } } }, { encryptionType: 'queryableEncryption' }));
601-
expectType<Schema>(new Schema({ name: { type: String, encrypt: { keyId } } }, { encryptionType: 'csfle' }));
600+
expectType<Schema>(new Schema<unknown>({ name: { type: String, encrypt: { keyId } } }, { encryptionType: 'queryableEncryption' }));
601+
expectType<Schema>(new Schema<unknown>({ name: { type: String, encrypt: { keyId } } }, { encryptionType: 'csfle' }));
602602
}
603603

604604
function gh11828() {
@@ -616,7 +616,7 @@ function gh11828() {
616616
}
617617
};
618618

619-
new Schema<IUser>({
619+
new Schema<unknown, IUser>({
620620
name: { type: String, default: () => 'Hafez' },
621621
age: { type: Number, default: () => 27 },
622622
bornAt: { type: Date, default: () => new Date() },
@@ -634,7 +634,7 @@ function gh11997() {
634634
name: string;
635635
}
636636

637-
const userSchema = new Schema<IUser>({
637+
const userSchema = new Schema<unknown, IUser>({
638638
name: { type: String, default: () => 'Hafez' }
639639
});
640640
userSchema.index({ name: 1 }, { weights: { name: 1 } });
@@ -664,7 +664,7 @@ function gh11987() {
664664
organization: Types.ObjectId;
665665
}
666666

667-
const userSchema = new Schema<IUser>({
667+
const userSchema = new Schema<unknown, IUser>({
668668
name: { type: String, required: true },
669669
email: { type: String, required: true },
670670
organization: { type: Schema.Types.ObjectId, ref: 'Organization' }
@@ -775,12 +775,12 @@ function pluginOptions() {
775775
option2: number;
776776
}
777777

778-
function pluginFunction(schema: Schema<any>, options: SomePluginOptions) {
778+
function pluginFunction(schema: Schema<any, any>, options: SomePluginOptions) {
779779
return; // empty function, to satisfy lint option
780780
}
781781

782782
const schema = new Schema({});
783-
expectType<Schema<any>>(schema.plugin(pluginFunction)); // test that chaining would be possible
783+
expectType<Schema<any, any>>(schema.plugin(pluginFunction)); // test that chaining would be possible
784784

785785
// could not add strict tests that the parameters are inferred correctly, because i dont know how this would be done in tsd
786786

@@ -1216,7 +1216,7 @@ function gh13800() {
12161216
type UserModel = Model<IUser, {}, IUserMethods>;
12171217

12181218
// Typed Schema
1219-
const schema = new Schema<IUser, UserModel, IUserMethods>({
1219+
const schema = new Schema<unknown, IUser, UserModel, IUserMethods>({
12201220
firstName: { type: String, required: true },
12211221
lastName: { type: String, required: true }
12221222
});
@@ -1243,7 +1243,7 @@ async function gh13797() {
12431243
interface IUser {
12441244
name: string;
12451245
}
1246-
new Schema<IUser>({
1246+
new Schema<unknown, IUser>({
12471247
name: {
12481248
type: String,
12491249
required: function() {
@@ -1252,7 +1252,7 @@ async function gh13797() {
12521252
}
12531253
}
12541254
});
1255-
new Schema<IUser>({
1255+
new Schema<unknown, IUser>({
12561256
name: {
12571257
type: String,
12581258
default: function() {
@@ -1293,7 +1293,7 @@ function gh14028_methods() {
12931293
type UserModel = Model<IUser, {}, IUserMethods>;
12941294

12951295
// Define methods on schema
1296-
const schema = new Schema<IUser, UserModel, IUserMethods>({
1296+
const schema = new Schema<unknown, IUser, UserModel, IUserMethods>({
12971297
firstName: { type: String, required: true },
12981298
lastName: { type: String, required: true },
12991299
age: { type: Number, required: true }
@@ -1323,7 +1323,7 @@ function gh14028_methods() {
13231323
expectType<IUserMethods['isAdult']>(schema.methods.isAdult);
13241324

13251325
// Define methods outside of schema
1326-
const schema2 = new Schema<IUser, UserModel, IUserMethods>({
1326+
const schema2 = new Schema<unknown, IUser, UserModel, IUserMethods>({
13271327
firstName: { type: String, required: true },
13281328
lastName: { type: String, required: true },
13291329
age: { type: Number, required: true }
@@ -1346,7 +1346,7 @@ function gh14028_methods() {
13461346

13471347
type UserModelWithoutMethods = Model<IUser>;
13481348
// Skip InstanceMethods
1349-
const schema3 = new Schema<IUser, UserModelWithoutMethods>({
1349+
const schema3 = new Schema<unknown, IUser, UserModelWithoutMethods>({
13501350
firstName: { type: String, required: true },
13511351
lastName: { type: String, required: true },
13521352
age: { type: Number, required: true }
@@ -1380,7 +1380,7 @@ function gh14028_statics() {
13801380
type UserModel = Model<IUser, {}>;
13811381

13821382
// Define statics on schema
1383-
const schema = new Schema<IUser, UserModel, {}, {}, {}, IUserStatics>({
1383+
const schema = new Schema<unknown, IUser, UserModel, {}, {}, {}, IUserStatics>({
13841384
firstName: { type: String, required: true },
13851385
lastName: { type: String, required: true },
13861386
age: { type: Number, required: true }
@@ -1434,7 +1434,7 @@ function gh14235() {
14341434
age: number;
14351435
}
14361436

1437-
const userSchema = new Schema<IUser>({ name: String, age: Number });
1437+
const userSchema = new Schema<unknown, IUser>({ name: String, age: Number });
14381438

14391439
userSchema.omit<Omit<IUser, 'age'>>(['age']);
14401440
}
@@ -1498,18 +1498,18 @@ function gh14573() {
14981498
type UserModelType = Model<User, {}, UserMethods, {}, THydratedUserDocument>;
14991499

15001500
const userSchema = new Schema<
1501+
unknown,
15011502
User,
15021503
UserModelType,
15031504
UserMethods,
15041505
{},
15051506
{},
15061507
{},
15071508
DefaultSchemaOptions,
1508-
User,
15091509
THydratedUserDocument
15101510
>(
15111511
{
1512-
names: new Schema<Names>({ firstName: String })
1512+
names: new Schema<unknown, Names>({ firstName: String })
15131513
},
15141514
{
15151515
methods: {
@@ -1562,7 +1562,7 @@ function gh14696() {
15621562
}
15631563

15641564
type UserModelType = Model<User, {}, IUserMethods>;
1565-
const userSchema = new Schema<User, UserModelType, IUserMethods>({
1565+
const userSchema = new Schema<unknown, User, UserModelType, IUserMethods>({
15661566
name: {
15671567
type: String,
15681568
required: [true, 'Name on card is required']
@@ -1787,7 +1787,7 @@ function gh15301() {
17871787
interface IUser {
17881788
time: { hours: number, minutes: number }
17891789
}
1790-
const userSchema = new Schema<IUser>({
1790+
const userSchema = new Schema<unknown, IUser>({
17911791
time: {
17921792
type: new Schema(
17931793
{
@@ -1831,7 +1831,7 @@ function gh15412() {
18311831
}
18321832

18331833
function defaultReturnsUndefined() {
1834-
const schema = new Schema<{ arr: number[] }>({
1834+
const schema = new Schema<unknown, { arr: number[] }>({
18351835
arr: {
18361836
type: [Number],
18371837
default: () => void 0

types/connection.d.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,17 @@ declare module 'mongoose' {
182182
collection?: string,
183183
options?: CompileModelOptions
184184
): Model<
185-
InferSchemaType<TSchema>,
186-
ObtainSchemaGeneric<TSchema, 'TQueryHelpers'>,
187-
ObtainSchemaGeneric<TSchema, 'TInstanceMethods'>,
188-
{},
189-
HydratedDocument<
190-
InferSchemaType<TSchema>,
191-
ObtainSchemaGeneric<TSchema, 'TInstanceMethods'>,
192-
ObtainSchemaGeneric<TSchema, 'TQueryHelpers'>
193-
>,
194-
TSchema> & ObtainSchemaGeneric<TSchema, 'TStaticMethods'>;
185+
InferSchemaType<TSchema>,
186+
ObtainSchemaGeneric<TSchema, 'TQueryHelpers'>,
187+
ObtainSchemaGeneric<TSchema, 'TInstanceMethods'>,
188+
{},
189+
HydratedDocument<
190+
InferSchemaType<TSchema>,
191+
ObtainSchemaGeneric<TSchema, 'TInstanceMethods'>,
192+
ObtainSchemaGeneric<TSchema, 'TQueryHelpers'>
193+
>,
194+
TSchema
195+
> & ObtainSchemaGeneric<TSchema, 'TStaticMethods'>;
195196
model<T, U, TQueryHelpers = {}>(
196197
name: string,
197198
schema?: Schema<any, T, U, any, TQueryHelpers, any, any, any>,

0 commit comments

Comments
 (0)