Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammad0-0ahmad committed Jun 3, 2022
1 parent e0d299f commit e137a6d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
12 changes: 6 additions & 6 deletions test/types/create.test.ts
Expand Up @@ -73,14 +73,14 @@ Test.insertMany([{ name: 'test' }], { rawResult: true }, (err, result) => {
expectType<CallbackError>(err);
expectType<boolean>(result.acknowledged);
expectType<number>(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<CallbackError>(err);
expectType<boolean>(result.acknowledged);
expectType<number>(result.insertedCount);
expectType<{[key: number]: Types.ObjectId;}>(result.insertedIds)
expectType<{ [key: number]: Types.ObjectId; }>(result.insertedIds);
});

Test.insertMany([{ name: 'test' }], { lean: true }, (err, docs) => {
Expand All @@ -103,7 +103,7 @@ Test.insertMany({ _id: '000000000000000000000000', name: 'test' }, (err, docs) =
expectType<boolean>(docs[0].isNew);
});

Test.insertMany({ _id: new Types.ObjectId('000000000000000000000000')}, (err, docs) => {
Test.insertMany({ _id: new Types.ObjectId('000000000000000000000000') }, (err, docs) => {
expectType<Types.ObjectId>(docs[0]._id);
expectType<string | undefined>(docs[0].name);
expectType<boolean>(docs[0].isNew);
Expand Down Expand Up @@ -136,13 +136,13 @@ Test.insertMany({ name: 'test' }, {}).then(docs => {
Test.insertMany([{ name: 'test' }], { rawResult: true }).then(result => {
expectType<boolean>(result.acknowledged);
expectType<number>(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<boolean>(result.acknowledged);
expectType<number>(result.insertedCount);
expectType<{[key: number]: Types.ObjectId;}>(result.insertedIds)
expectType<{ [key: number]: Types.ObjectId; }>(result.insertedIds);
});

Test.insertMany([{ name: 'test' }], { lean: true }).then(docs => {
Expand Down Expand Up @@ -181,7 +181,7 @@ Test.insertMany({ _id: new Types.ObjectId('000000000000000000000000'), name: 'te
expectType<boolean>(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];
Expand Down
14 changes: 7 additions & 7 deletions 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<string>({} as MergeType<B, A>["a"]);
expectType<string>({} as MergeType<B, A>["b"]);
expectType<number>({} as MergeType<B, A>["c"]);
expectType<string>({} as MergeType<B, A>['a']);
expectType<string>({} as MergeType<B, A>['b']);
expectType<number>({} as MergeType<B, A>['c']);

expectType<number>({} as MergeType<A, B>["a"]);
expectType<string>({} as MergeType<A, B>["b"]);
expectType<number>({} as MergeType<A, B>["c"]);
expectType<number>({} as MergeType<A, B>['a']);
expectType<string>({} as MergeType<A, B>['b']);
expectType<number>({} as MergeType<A, B>['c']);
12 changes: 6 additions & 6 deletions types/index.d.ts
Expand Up @@ -101,15 +101,15 @@ declare module 'mongoose' {
[k: string]: any
}

export type Require_id<T> = T extends { _id?: infer U }
export type Require_id<T> = 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> = T extends { _id?: infer U; }
? Required<{ _id: U }>
: { _id: Types.ObjectId };

export type RequireOnlyTypedId<T> = T extends { _id?: infer U; }
? Required<{ _id: U }>
: { _id: Types.ObjectId };

export type HydratedDocument<DocType, TMethodsAndOverrides = {}, TVirtuals = {}> = DocType extends Document ? Require_id<DocType> : (Document<unknown, any, DocType> & Require_id<DocType> & TVirtuals & TMethodsAndOverrides);

Expand Down
4 changes: 2 additions & 2 deletions types/utility.d.ts
Expand Up @@ -7,8 +7,8 @@ declare module 'mongoose' {
type UnpackedIntersection<T, U> = T extends null ? null : T extends (infer A)[]
? (Omit<A, keyof U> & U)[]
: keyof U extends never
? T
: Omit<T, keyof U> & U;
? T
: Omit<T, keyof U> & U;

type MergeType<A extends Record<number | string, any>, B extends Record<number | string, any>> = Omit<A, keyof B> & B;

Expand Down

0 comments on commit e137a6d

Please sign in to comment.