Skip to content

Commit

Permalink
Merge pull request #9958 from ShadiestGoat/master
Browse files Browse the repository at this point in the history
A simple PR that adds enforcing onto schema
  • Loading branch information
vkarpov15 authored Feb 22, 2021
2 parents 09c3850 + f02a5ef commit 9d396d2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1188,14 +1188,15 @@ declare module 'mongoose' {
virtualpath(name: string): VirtualType | null;
}

type SchemaDefinitionWithBuiltInClass<T> = T extends number
type SchemaDefinitionWithBuiltInClass<T extends number | string | Function> = T extends number
? (typeof Number | 'number' | 'Number')
: T extends string
? (typeof String | 'string' | 'String')
: (Function | string);

type SchemaDefinitionProperty<T = undefined> = SchemaTypeOptions<T extends undefined ? any : T> |
SchemaDefinitionWithBuiltInClass<T> |
type SchemaDefinitionProperty<T = undefined> = T extends string | number | Function
? (SchemaDefinitionWithBuiltInClass<T> | SchemaTypeOptions<T>) :
SchemaTypeOptions<T extends undefined ? any : T> |
typeof SchemaType |
Schema<T extends Document ? T : Document<any>> |
Schema<T extends Document ? T : Document<any>>[] |
Expand Down Expand Up @@ -1371,7 +1372,7 @@ declare module 'mongoose' {
}

interface SchemaTypeOptions<T> {
type?: T | SchemaDefinitionWithBuiltInClass<T>;
type?: T extends string | number | Function ? SchemaDefinitionWithBuiltInClass<T> : T;

/** Defines a virtual with the given name that gets/sets this path. */
alias?: string;
Expand Down Expand Up @@ -2655,4 +2656,4 @@ declare module 'mongoose' {

/* for ts-mongoose */
class mquery {}
}
}

0 comments on commit 9d396d2

Please sign in to comment.