Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A simple PR that adds enforcing onto schema #9958

Merged
merged 7 commits into from
Feb 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1182,14 +1182,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 @@ -1365,7 +1366,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 @@ -2648,4 +2649,4 @@ declare module 'mongoose' {

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