From 98d75d44bffc722aa139abbc7bc4442ee17006f4 Mon Sep 17 00:00:00 2001 From: mohammad0-0ahmad Date: Fri, 3 Jun 2022 16:30:27 +0200 Subject: [PATCH] Fix linting --- test/types/create.test.ts | 12 ++++---- test/types/utility.test.ts | 14 ++++----- types/index.d.ts | 12 ++++---- types/models.d.ts | 58 +++++++++++++++++++------------------- types/utility.d.ts | 4 +-- 5 files changed, 50 insertions(+), 50 deletions(-) diff --git a/test/types/create.test.ts b/test/types/create.test.ts index 9665c88f837..debca167aeb 100644 --- a/test/types/create.test.ts +++ b/test/types/create.test.ts @@ -73,14 +73,14 @@ Test.insertMany([{ name: 'test' }], { rawResult: true }, (err, result) => { expectType(err); expectType(result.acknowledged); expectType(result.insertedCount); - expectType<{[key: number]: Types.ObjectId;}>(result.insertedIds) + expectType<{ [key: number]: Types.ObjectId; }>(result.insertedIds); }); Test.insertMany([{ name: 'test' }], { rawResult: true }, (err, result) => { expectType(err); expectType(result.acknowledged); expectType(result.insertedCount); - expectType<{[key: number]: Types.ObjectId;}>(result.insertedIds) + expectType<{ [key: number]: Types.ObjectId; }>(result.insertedIds); }); Test.insertMany([{ name: 'test' }], { lean: true }, (err, docs) => { @@ -103,7 +103,7 @@ Test.insertMany({ _id: '000000000000000000000000', name: 'test' }, (err, docs) = expectType(docs[0].isNew); }); -Test.insertMany({ _id: new Types.ObjectId('000000000000000000000000')}, (err, docs) => { +Test.insertMany({ _id: new Types.ObjectId('000000000000000000000000') }, (err, docs) => { expectType(docs[0]._id); expectType(docs[0].name); expectType(docs[0].isNew); @@ -136,13 +136,13 @@ Test.insertMany({ name: 'test' }, {}).then(docs => { Test.insertMany([{ name: 'test' }], { rawResult: true }).then(result => { expectType(result.acknowledged); expectType(result.insertedCount); - expectType<{[key: number]: Types.ObjectId;}>(result.insertedIds) + expectType<{ [key: number]: Types.ObjectId; }>(result.insertedIds); }); Test.insertMany([{ name: 'test' }], { rawResult: true }).then(result => { expectType(result.acknowledged); expectType(result.insertedCount); - expectType<{[key: number]: Types.ObjectId;}>(result.insertedIds) + expectType<{ [key: number]: Types.ObjectId; }>(result.insertedIds); }); Test.insertMany([{ name: 'test' }], { lean: true }).then(docs => { @@ -181,7 +181,7 @@ Test.insertMany({ _id: new Types.ObjectId('000000000000000000000000'), name: 'te expectType(docs[0].isNew); }); -(async () => { +(async() => { const [t1] = await Test.create([{ name: 'test' }]); const [t2, t3, t4] = await Test.create({ name: 'test' }, { name: 'test' }, { name: 'test' }); (await Test.create([{ name: 'test' }]))[0]; diff --git a/test/types/utility.test.ts b/test/types/utility.test.ts index bc07a6c22be..03dc3d7e9af 100644 --- a/test/types/utility.test.ts +++ b/test/types/utility.test.ts @@ -1,13 +1,13 @@ import { MergeType } from 'mongoose'; import { expectType } from 'tsd'; -type A = { a: string, c: number}; +type A = { a: string, c: number }; type B = { a: number, b: string }; -expectType({} as MergeType["a"]); -expectType({} as MergeType["b"]); -expectType({} as MergeType["c"]); +expectType({} as MergeType['a']); +expectType({} as MergeType['b']); +expectType({} as MergeType['c']); -expectType({} as MergeType["a"]); -expectType({} as MergeType["b"]); -expectType({} as MergeType["c"]); +expectType({} as MergeType['a']); +expectType({} as MergeType['b']); +expectType({} as MergeType['c']); diff --git a/types/index.d.ts b/types/index.d.ts index 09e99ff7b48..46e4cbc22f5 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -101,15 +101,15 @@ declare module 'mongoose' { [k: string]: any } - export type Require_id = T extends { _id?: infer U } + export type Require_id = T extends { _id?: infer U } ? U extends any ? (T & { _id: Types.ObjectId }) - : T & Required<{ _id: U }> + : T & Required<{ _id: U }> : T & { _id: Types.ObjectId }; - - export type RequireOnlyTypedId = T extends { _id?: infer U; } - ? Required<{ _id: U }> - : { _id: Types.ObjectId }; + + export type RequireOnlyTypedId = T extends { _id?: infer U; } + ? Required<{ _id: U }> + : { _id: Types.ObjectId }; export type HydratedDocument = DocType extends Document ? Require_id : (Document & Require_id & TVirtuals & TMethodsAndOverrides); diff --git a/types/models.d.ts b/types/models.d.ts index cf539cbb03d..783a5653bf3 100644 --- a/types/models.d.ts +++ b/types/models.d.ts @@ -121,11 +121,11 @@ declare module 'mongoose' { SessionStarter { new (doc?: DocType, fields?: any | null, options?: boolean | AnyObject): HydratedDocument, TMethodsAndOverrides, TVirtuals> & ObtainSchemaGeneric; - aggregate(pipeline?: PipelineStage[], options?: mongodb.AggregateOptions, callback?: Callback): Aggregate>; - aggregate(pipeline: PipelineStage[], callback?: Callback): Aggregate>; + aggregate(pipeline?: PipelineStage[], options?: mongodb.AggregateOptions, callback?: Callback): Aggregate>; + aggregate(pipeline: PipelineStage[], callback?: Callback): Aggregate>; - /** Base Mongoose instance the model uses. */ - base: Mongoose; + /** Base Mongoose instance the model uses. */ + base: Mongoose; /** * If this is a discriminator model, `baseModelName` is the name of @@ -178,8 +178,8 @@ declare module 'mongoose' { createCollection(callback: Callback>): void; createCollection(options?: mongodb.CreateCollectionOptions & Pick): Promise>; - /** Connection the model uses. */ - db: Connection; + /** Connection the model uses. */ + db: Connection; /** * Deletes all of the documents that match `conditions` from the collection. @@ -272,38 +272,38 @@ declare module 'mongoose' { insertMany(doc: DocContents, options: InsertManyOptions): Promise, RequireOnlyTypedId>, TMethodsAndOverrides, TVirtuals>>>; insertMany(doc: DocContents): Promise, RequireOnlyTypedId>, TMethodsAndOverrides, TVirtuals>>>; - /** The name of the model */ - modelName: string; + /** The name of the model */ + modelName: string; - /** Populates document references. */ - populate(docs: Array, options: PopulateOptions | Array | string, - callback?: Callback<(HydratedDocument)[]>): Promise>>; - populate(doc: any, options: PopulateOptions | Array | string, - callback?: Callback>): Promise>; + /** Populates document references. */ + populate(docs: Array, options: PopulateOptions | Array | string, + callback?: Callback<(HydratedDocument)[]>): Promise>>; + populate(doc: any, options: PopulateOptions | Array | string, + callback?: Callback>): Promise>; - /** Casts and validates the given object against this model's schema, passing the given `context` to custom validators. */ - validate(callback?: CallbackWithoutResult): Promise; - validate(optional: any, callback?: CallbackWithoutResult): Promise; - validate(optional: any, pathsToValidate: PathsToValidate, callback?: CallbackWithoutResult): Promise; + /** Casts and validates the given object against this model's schema, passing the given `context` to custom validators. */ + validate(callback?: CallbackWithoutResult): Promise; + validate(optional: any, callback?: CallbackWithoutResult): Promise; + validate(optional: any, pathsToValidate: PathsToValidate, callback?: CallbackWithoutResult): Promise; - /** Watches the underlying collection for changes using [MongoDB change streams](https://docs.mongodb.com/manual/changeStreams/). */ - watch(pipeline?: Array>, options?: mongodb.ChangeStreamOptions): mongodb.ChangeStream; + /** Watches the underlying collection for changes using [MongoDB change streams](https://docs.mongodb.com/manual/changeStreams/). */ + watch(pipeline?: Array>, options?: mongodb.ChangeStreamOptions): mongodb.ChangeStream; - /** Adds a `$where` clause to this query */ - $where(argument: string | Function): QueryWithHelpers>, HydratedDocument, TQueryHelpers, T>; + /** Adds a `$where` clause to this query */ + $where(argument: string | Function): QueryWithHelpers>, HydratedDocument, TQueryHelpers, T>; - /** Registered discriminators for this model. */ - discriminators: { [name: string]: Model } | undefined; + /** Registered discriminators for this model. */ + discriminators: { [name: string]: Model } | undefined; - /** Translate any aliases fields/conditions so the final query or document object is pure */ - translateAliases(raw: any): any; + /** Translate any aliases fields/conditions so the final query or document object is pure */ + translateAliases(raw: any): any; - /** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */ - distinct(field: string, filter?: FilterQuery, callback?: Callback): QueryWithHelpers, HydratedDocument, TQueryHelpers, T>; + /** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */ + distinct(field: string, filter?: FilterQuery, callback?: Callback): QueryWithHelpers, HydratedDocument, TQueryHelpers, T>; - /** Creates a `estimatedDocumentCount` query: counts the number of documents in the collection. */ - estimatedDocumentCount(options?: QueryOptions, callback?: Callback): QueryWithHelpers, TQueryHelpers, T>; + /** Creates a `estimatedDocumentCount` query: counts the number of documents in the collection. */ + estimatedDocumentCount(options?: QueryOptions, callback?: Callback): QueryWithHelpers, TQueryHelpers, T>; /** * Returns a document with its `_id` if at least one document exists in the database that matches diff --git a/types/utility.d.ts b/types/utility.d.ts index 5997b71b7ca..d18c9f228db 100644 --- a/types/utility.d.ts +++ b/types/utility.d.ts @@ -7,8 +7,8 @@ declare module 'mongoose' { type UnpackedIntersection = T extends null ? null : T extends (infer A)[] ? (Omit & U)[] : keyof U extends never - ? T - : Omit & U; + ? T + : Omit & U; type MergeType, B extends Record> = Omit & B;