From 7eb3b5f4edc6443c8b4dd9b1bdd83704ffc8bb1d Mon Sep 17 00:00:00 2001 From: mernxl Date: Sat, 4 Aug 2018 14:25:16 +0100 Subject: [PATCH] FixType(mongoose): fix minor syntax issues and make options nonNullable in v3 Check ensure by linting --- types/mongoose/mongoose-tests.ts | 14 +++++++------- types/mongoose/v3/index.d.ts | 8 ++++---- types/mongoose/v4/mongoose-tests.ts | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/types/mongoose/mongoose-tests.ts b/types/mongoose/mongoose-tests.ts index eaee271448..2fe1e1b12e 100644 --- a/types/mongoose/mongoose-tests.ts +++ b/types/mongoose/mongoose-tests.ts @@ -293,7 +293,7 @@ schema.method('name', cb).method({ }); schema.path('a', mongoose.Schema.Types.Buffer).path('a'); schema.pathType('m1').toLowerCase(); -schema.plugin(function (schema, opts) { +schema.plugin(function (schema: mongoose.Schema, opts?: any) { schema.get('path'); if (opts) { opts.hasOwnProperty(''); @@ -564,25 +564,25 @@ new mongoose.Schema({ } }); -(new mongoose.Schema({})).plugin(function (schema: any, options: any) { +(new mongoose.Schema({})).plugin(function (schema: mongoose.Schema, options: any) { schema.add({ lastMod: Date }) schema.pre('save', function (next: Function) { - this.lastMod = new Date + (this as any).lastMod = new Date next() }) if (options && options['index']) { schema.path('lastMod').index(options['index']) } -}, { index: true }).plugin(function (schema: any, options: any) { +}, { index: true }).plugin(function (schema: mongoose.Schema, options: any) { schema.add({ lastMod: Date }) schema.pre('save', function (next: Function) { - this.lastMod = new Date + (this as any).lastMod = new Date next() }) if (options && options['index']) { schema.path('lastMod').index(options['index']) } -}); +}, {index: true}); new mongoose.Schema({foo: String}, {strict: 'throw'}); @@ -595,7 +595,7 @@ export default function(schema: mongoose.Schema) { // plugins function MyPlugin(schema: mongoose.Schema, opts?: string) { } -mongoose.Schema({}) +new mongoose.Schema({}) .plugin(MyPlugin) interface PluginOption { diff --git a/types/mongoose/v3/index.d.ts b/types/mongoose/v3/index.d.ts index 2c8232f21d..40e254deda 100644 --- a/types/mongoose/v3/index.d.ts +++ b/types/mongoose/v3/index.d.ts @@ -14,8 +14,8 @@ declare module "mongoose" { function model(name: string, schema?: Schema, collection?: string, skipInit?: boolean): Model; function modelNames(): string[]; - function plugin(plugin: (schema: Schema) => void): Mongoose - function plugin(plugin: (schema: Schema, options?: T) => void, options?: T): Mongoose; + function plugin(plugin: (schema: Schema) => void): Mongoose; + function plugin(plugin: (schema: Schema, options: T) => void, options: T): Mongoose; function get(key: string): any; function set(key: string, value: any): void; @@ -35,7 +35,7 @@ declare module "mongoose" { model(name: string, schema?: Schema, collection?: string, skipInit?: boolean): Model; modelNames(): string[]; plugin(plugin: (schema: Schema) => void): Mongoose; - plugin(plugin: (schema: Schema, options?: T) => void, options?: T): Mongoose; + plugin(plugin: (schema: Schema, options: T) => void, options: T): Mongoose; set(key: string, value: any): void; mongo: any; @@ -276,7 +276,7 @@ declare module "mongoose" { path(path: string, constructor: any): Schema; pathType(path: string): string; plugin(plugin: (schema: Schema) => void): Schema; - plugin(plugin: (schema: Schema, options?: T) => void, options?: T): Schema; + plugin(plugin: (schema: Schema, options: T) => void, options: T): Schema; pre(method: string, fn: HookSyncCallback, errorCb?: HookErrorCallback): Schema; pre(method: string, isAsync: boolean, fn: HookAsyncCallback, errorCb?: HookErrorCallback): Schema; diff --git a/types/mongoose/v4/mongoose-tests.ts b/types/mongoose/v4/mongoose-tests.ts index ddf96848b9..b2d2a834fd 100644 --- a/types/mongoose/v4/mongoose-tests.ts +++ b/types/mongoose/v4/mongoose-tests.ts @@ -262,7 +262,7 @@ schema.method('name', cb).method({ }); schema.path('a', mongoose.Schema.Types.Buffer).path('a'); schema.pathType('m1').toLowerCase(); -schema.plugin(function (schema, opts) { +schema.plugin(function (schema: mongoose.Schema, opts?: any) { schema.get('path'); if (opts) { opts.hasOwnProperty(''); @@ -424,7 +424,7 @@ new mongoose.Schema({ if (options && options['index']) { schema.path('lastMod').index(options['index']) } -}); +}, {index: true}); // plugins interface PluginOption {