Skip to content
Closed
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions test/types/exportedTypes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Projector, ArrayOperators, QueryResultType, PluginFunction, Query, Schema } from 'mongoose';
Copy link

Copilot AI Apr 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Schema is imported but never used in this type test, and all mongoose imports here are used only in type positions. Consider removing the unused Schema import and switching the mongoose import to an import type to match other type-test files and avoid generating a runtime import if these tests are ever emitted.

Suggested change
import { Projector, ArrayOperators, QueryResultType, PluginFunction, Query, Schema } from 'mongoose';
import type { Projector, ArrayOperators, QueryResultType, PluginFunction, Query } from 'mongoose';

Copilot uses AI. Check for mistakes.
import { expect } from 'tstyche';

// Test Projector is exported and works correctly
type TestProjection = Projector<{ name: string; age: number }, true>;
expect<TestProjection['name']>().type.toBe<true | undefined>();
expect<TestProjection['age']>().type.toBe<true | undefined>();

// Test ArrayOperators is exported
expect<ArrayOperators['$slice']>().type.toBe<number | [number, number] | undefined>();

// Test QueryResultType is exported
type TestQuery = Query<string[], string>;
expect<QueryResultType<TestQuery>>().type.toBe<string[]>();

// Test PluginFunction is exported
type TestPlugin = PluginFunction<{ name: string }, any, any, any, any, any>;
expect<ReturnType<TestPlugin>>().type.toBe<void>();

Check warning on line 18 in test/types/exportedTypes.test.ts

View workflow job for this annotation

GitHub Actions / Lint TS-Files

Newline required at end of file but not found
8 changes: 4 additions & 4 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ declare module 'mongoose' {
? Schema<MergeType<DocType, DisSchemaEDocType>, DiscriminatorModel<DisSchemaM, M>, DisSchemaInstanceMethods | TInstanceMethods, DisSchemaQueryhelpers | TQueryHelpers, DisSchemaVirtuals | TVirtuals, DisSchemaStatics & TStaticMethods>
: Schema<DocType, M, TInstanceMethods, TQueryHelpers, TVirtuals, TStaticMethods>;

type QueryResultType<T> = T extends Query<infer ResultType, any> ? ResultType : never;
export type QueryResultType<T> = T extends Query<infer ResultType, any> ? ResultType : never;

type PluginFunction<
export type PluginFunction<
DocType,
M,
TInstanceMethods,
Expand Down Expand Up @@ -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<string, any>; $slice?: never };
export type ArrayOperators = { $slice: number | [number, number]; $elemMatch?: never } | { $elemMatch: Record<string, any>; $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.
Expand All @@ -836,7 +836,7 @@ declare module 'mongoose' {
d?: true | ArrayOperators | undefined;
}
*/
type Projector<T, Element> = T extends Array<infer U>
export type Projector<T, Element> = T extends Array<infer U>
? Projector<U, Element> | ArrayOperators
: T extends TreatAsPrimitives
? Element
Expand Down