From b41d94cdd229b584982ced69ccba99cc28631a36 Mon Sep 17 00:00:00 2001 From: Roberts Slisans Date: Thu, 29 Jun 2017 12:11:38 +0300 Subject: [PATCH 1/3] Fixed test case to a real world scenario, and subsequently fixed type definition --- types/mongoose-simple-random/index.d.ts | 6 ++++++ .../mongoose-simple-random/mongoose-simple-random-tests.ts | 3 +++ 2 files changed, 9 insertions(+) diff --git a/types/mongoose-simple-random/index.d.ts b/types/mongoose-simple-random/index.d.ts index deed6a036f..a57f366df2 100644 --- a/types/mongoose-simple-random/index.d.ts +++ b/types/mongoose-simple-random/index.d.ts @@ -4,6 +4,12 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// +declare module 'mongoose-simple-random' { + import mongoose = require('mongoose'); + var _: (schema: mongoose.Schema) => void; + export = _; +} + declare module "mongoose" { interface Model extends NodeJS.EventEmitter, ModelProperties { findRandom(conditions: Object, projection?: Object | null, options?: Object | null, callback?: (err: any, res: T[]) => void) diff --git a/types/mongoose-simple-random/mongoose-simple-random-tests.ts b/types/mongoose-simple-random/mongoose-simple-random-tests.ts index 2aa9e18296..f5b26dbebb 100644 --- a/types/mongoose-simple-random/mongoose-simple-random-tests.ts +++ b/types/mongoose-simple-random/mongoose-simple-random-tests.ts @@ -1,4 +1,5 @@ import * as mongoose from 'mongoose'; +import * as mongoose_simple_random from "mongoose-simple-random"; // test compatibility with other libraries - from @types/mongoose import * as _ from 'lodash'; @@ -13,3 +14,5 @@ mongoose.Model.findRandom({ }, {}, { limit: 1 }, (error, data) => { if (error) { console.error("Error!"); } else { console.log("Success!"); } }); + +mongoose.plugin(mongoose_simple_random); From ee28ce2e1378d8c7031682f06a39525805ce8840 Mon Sep 17 00:00:00 2001 From: Roberts Slisans Date: Thu, 29 Jun 2017 12:35:10 +0300 Subject: [PATCH 2/3] Fix tslint errors --- types/mongoose-simple-random/index.d.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/types/mongoose-simple-random/index.d.ts b/types/mongoose-simple-random/index.d.ts index a57f366df2..4625f582d1 100644 --- a/types/mongoose-simple-random/index.d.ts +++ b/types/mongoose-simple-random/index.d.ts @@ -2,12 +2,11 @@ // Project: https://github.com/larryprice/mongoose-simple-random // Definitions by: My Self // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// declare module 'mongoose-simple-random' { import mongoose = require('mongoose'); - var _: (schema: mongoose.Schema) => void; - export = _; + function plugin(schema: mongoose.Schema): void; + export = plugin; } declare module "mongoose" { From dcda58e335071d4f24e288d737802997c20eb653 Mon Sep 17 00:00:00 2001 From: Roberts Slisans Date: Thu, 29 Jun 2017 13:10:22 +0300 Subject: [PATCH 3/3] Found a way. --- types/mongoose-simple-random/index.d.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/types/mongoose-simple-random/index.d.ts b/types/mongoose-simple-random/index.d.ts index 4625f582d1..16b1c21483 100644 --- a/types/mongoose-simple-random/index.d.ts +++ b/types/mongoose-simple-random/index.d.ts @@ -5,7 +5,11 @@ declare module 'mongoose-simple-random' { import mongoose = require('mongoose'); - function plugin(schema: mongoose.Schema): void; + // Dummy function allows to avoid hard to kill or fix tslint warning + // (exporting pluginFunc will make this a non-importable module) + function pluginFunc(schema: mongoose.Schema): void; + // Let allows typescript to still use ES2015 style imports + let plugin: typeof pluginFunc; export = plugin; }