Skip to content

Commit

Permalink
Refactor some lines in ResolvePathType helper related to objectId
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammad0-0ahmad committed Jul 4, 2022
1 parent 5f9f79c commit 3feb8af
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion test/types/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ export function autoTypedSchema() {
mixed3: Schema.Types.Mixed,
objectId1: Schema.Types.ObjectId,
objectId2: 'ObjectId',
objectId3: 'objectId',
objectId3: 'ObjectID',
customSchema: Int8,
map1: { type: Map, of: String },
map2: { type: Map, of: Number },
Expand Down
7 changes: 4 additions & 3 deletions types/inferschematype.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
BooleanSchemaDefinition,
DateSchemaDefinition,
ObtainDocumentType,
DefaultTypeKey
DefaultTypeKey,
ObjectIdSchemaDefinition
} from 'mongoose';

declare module 'mongoose' {
Expand Down Expand Up @@ -166,7 +167,7 @@ type PathEnumOrString<T extends SchemaTypeOptions<string>['enum']> = T extends (
* @param {PathValueType} PathValueType Document definition path type.
* @param {Options} Options Document definition path options except path type.
* @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
* @returns Number, "Number" or "number" will be resolved to string type.
* @returns Number, "Number" or "number" will be resolved to number type.
*/
type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueType> = {}, TypeKey extends TypeKeyBaseType = DefaultTypeKey> =
PathValueType extends Schema ? InferSchemaType<PathValueType> :
Expand All @@ -176,7 +177,7 @@ type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueT
PathValueType extends DateSchemaDefinition ? Date :
PathValueType extends typeof Buffer | 'buffer' | 'Buffer' | typeof Schema.Types.Buffer ? Buffer :
PathValueType extends BooleanSchemaDefinition ? boolean :
PathValueType extends 'objectId' | 'ObjectId' | typeof Schema.Types.ObjectId ? Types.ObjectId :
PathValueType extends ObjectIdSchemaDefinition ? Types.ObjectId :
PathValueType extends 'decimal128' | 'Decimal128' | typeof Schema.Types.Decimal128 ? Types.Decimal128 :
PathValueType extends MapConstructor ? Map<string, ResolvePathType<Options['of']>> :
PathValueType extends ArrayConstructor ? any[] :
Expand Down

0 comments on commit 3feb8af

Please sign in to comment.