diff --git a/test/types/exportedTypes.test.ts b/test/types/exportedTypes.test.ts new file mode 100644 index 0000000000..32e15f1d92 --- /dev/null +++ b/test/types/exportedTypes.test.ts @@ -0,0 +1,18 @@ +import { Projector, ArrayOperators, QueryResultType, PluginFunction, Query, Schema } from 'mongoose'; +import { expect } from 'tstyche'; + +// Test Projector is exported and works correctly +type TestProjection = Projector<{ name: string; age: number }, true>; +expect().type.toBe(); +expect().type.toBe(); + +// Test ArrayOperators is exported +expect().type.toBe(); + +// Test QueryResultType is exported +type TestQuery = Query; +expect>().type.toBe(); + +// Test PluginFunction is exported +type TestPlugin = PluginFunction<{ name: string }, any, any, any, any, any>; +expect>().type.toBe(); \ No newline at end of file diff --git a/types/index.d.ts b/types/index.d.ts index 71aee6cbf0..781625c29c 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -288,9 +288,9 @@ declare module 'mongoose' { ? Schema, DiscriminatorModel, DisSchemaInstanceMethods | TInstanceMethods, DisSchemaQueryhelpers | TQueryHelpers, DisSchemaVirtuals | TVirtuals, DisSchemaStatics & TStaticMethods> : Schema; - type QueryResultType = T extends Query ? ResultType : never; + export type QueryResultType = T extends Query ? ResultType : never; - type PluginFunction< + export type PluginFunction< DocType, M, TInstanceMethods, @@ -819,7 +819,7 @@ declare module 'mongoose' { export type ReturnsNewDoc = { new: true } | { returnOriginal: false } | { returnDocument: 'after' }; - type ArrayOperators = { $slice: number | [number, number]; $elemMatch?: never } | { $elemMatch: Record; $slice?: never }; + export type ArrayOperators = { $slice: number | [number, number]; $elemMatch?: never } | { $elemMatch: Record; $slice?: never }; /** * This Type Assigns `Element | undefined` recursively to the `T` type. * if it is an array it will do this to the element of the array, if it is an object it will do this for the properties of the object. @@ -836,7 +836,7 @@ declare module 'mongoose' { d?: true | ArrayOperators | undefined; } */ - type Projector = T extends Array + export type Projector = T extends Array ? Projector | ArrayOperators : T extends TreatAsPrimitives ? Element