diff --git a/mongoose/index.d.ts b/mongoose/index.d.ts index a0508e7223..92655b871d 100644 --- a/mongoose/index.d.ts +++ b/mongoose/index.d.ts @@ -748,6 +748,18 @@ declare module "mongoose" { * ... * } * }); + * + * Note: the properties have Object as a fallback type: | Object + * because this interface does not apply to a schematype that + * does not have a type property. Ex: + * new Schema({ + * name: { + * first: String, // since name does not have a "type" property + * last: String // first and last can have any valid type + * ... + * } + * }); + * * References: * - http://mongoosejs.com/docs/schematypes.html * - http://mongoosejs.com/docs/api.html#schema_Schema.Types @@ -763,7 +775,7 @@ declare module "mongoose" { * Getters allow you to transform the representation of the data as it travels * from the raw mongodb document to the value that you see. */ - get?: (value: T, schematype?: this) => T; + get?: (value: T, schematype?: this) => T | Object; /** Declares the index options for this schematype. */ index?: SchemaTypeOpts.IndexOpts | boolean | string; @@ -774,7 +786,8 @@ declare module "mongoose" { */ required?: SchemaTypeOpts.RequiredFn | boolean | [boolean, string] | - string | [string, string]; + string | [string, string] | + Object; /** * Sets default select() behavior for this path. @@ -782,19 +795,19 @@ declare module "mongoose" { * if it should be excluded by default. This setting can be overridden at * the query level. */ - select?: boolean; + select?: boolean | Object; /** * Setters allow you to transform the data before it gets to the raw mongodb * document and is set as a value on an actual key. */ - set?: (value: T, schematype?: this) => T; + set?: (value: T, schematype?: this) => T | Object; /** Declares a sparse index. */ - sparse?: boolean; + sparse?: boolean | Object; /** Declares a full text index. */ - text?: boolean; + text?: boolean | Object; /** * Adds validator(s) for this document path. @@ -803,50 +816,53 @@ declare module "mongoose" { */ validate?: RegExp | [RegExp, string] | SchemaTypeOpts.ValidateFn | [SchemaTypeOpts.ValidateFn, string] | - SchemaTypeOpts.ValidateOpts | SchemaTypeOpts.ValidateOpts[]; + SchemaTypeOpts.ValidateOpts | SchemaTypeOpts.ValidateOpts[] | + Object; /** Declares an unique index. */ - unique?: boolean; + unique?: boolean | Object; /* Options for specific schema types (String, Number, Date, etc.) */ /** String only - Adds an enum validator */ - enum?: T[] | SchemaTypeOpts.EnumOpts; + enum?: T[] | SchemaTypeOpts.EnumOpts | Object; /** String only - Adds a lowercase setter. */ - lowercase?: boolean; + lowercase?: boolean | Object; /** String only - Sets a regexp validator. */ - match?: RegExp | [RegExp, string]; + match?: RegExp | [RegExp, string] | Object; /** String only - Sets a maximum length validator. */ - maxlength?: number | [number, string]; + maxlength?: number | [number, string] | Object; /** String only - Sets a minimum length validator. */ - minlength?: number | [number, string]; + minlength?: number | [number, string] | Object; /** String only - Adds a trim setter. */ - trim?: boolean; + trim?: boolean | Object; /** String only - Adds an uppercase setter. */ - uppercase?: boolean; + uppercase?: boolean | Object; /** * Date, Number only - Sets a minimum number validator. * Sets a minimum date validator. */ min?: number | [number, string] | - Date | [Date, string]; + Date | [Date, string] | + Object; /** * Date, Number only - Sets a maximum number validator. * Sets a maximum date validator. */ max?: number | [number, string] | - Date | [Date, string]; + Date | [Date, string] | + Object; /** * Date only - Declares a TTL index (rounded to the nearest second) * for Date types only. */ - expires?: number | string; + expires?: number | string | Object; /** ObjectId only - Adds an auto-generated ObjectId default if turnOn is true. */ - auto?: boolean; + auto?: boolean | Object; [other: string]: any; } diff --git a/mongoose/mongoose-tests.ts b/mongoose/mongoose-tests.ts index 95badddedd..be63241296 100644 --- a/mongoose/mongoose-tests.ts +++ b/mongoose/mongoose-tests.ts @@ -318,7 +318,14 @@ new mongoose.Schema({ hidden: Boolean, meta: { votes: Number, - favs: Number + favs: Number, + text: String + }, + meta2: { + text: mongoose.Schema.Types.Number, + select: { + type: String + } } }); new mongoose.Schema({ name: { type: String, index: true }});