You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
both resolve the issue, i dont understand why typescript complains, but the mentioned solution(s) above resolve it for this case, but i dont know if this would break some types tests
full error (from the reproduce script):
src/test.ts:11:12 - error TS2677: A type predicate's type must be assignable to its parameter's type.
Type 'Array<S>' is not assignable to type 'Array<PopulatedDoc<T, S>>'.
Types of property 'toObject' are incompatible.
Type '{ (options?: ToObjectOptions<S> | undefined): any; <T>(options?: ToObjectOptions<T> | undefined): T; }' is not assignable to type '{ (options?: ToObjectOptions<PopulatedDoc<T, S>> | undefined): any; <T>(options?: ToObjectOptions<T> | undefined): T; }'.
Types of parameters 'options' and 'options' are incompatible.
Type 'ToObjectOptions<PopulatedDoc<T, S>> | undefined' is not assignable to type 'ToObjectOptions<S> | undefined'.
Type 'ToObjectOptions<PopulatedDoc<T, S>>' is not assignable to type 'ToObjectOptions<S>'.
Types of property 'transform' are incompatible.
Type 'boolean | ((doc: PopulatedDoc<T, S>, ret: Record<string, any>, options: ToObjectOptions<PopulatedDoc<T, S>>) => any) | undefined' is not assignable to type 'boolean | ((doc: S, ret: Record<string, any>, options: ToObjectOptions<S>) => any) | undefined'.
Type '(doc: PopulatedDoc<T, S>, ret: Record<string, any>, options: ToObjectOptions<PopulatedDoc<T, S>>) => any' is not assignable to type 'boolean | ((doc: S, ret: Record<string, any>, options: ToObjectOptions<S>) => any) | undefined'.
Type '(doc: PopulatedDoc<T, S>, ret: Record<string, any>, options: ToObjectOptions<PopulatedDoc<T, S>>) => any' is not assignable to type '(doc: S, ret: Record<string, any>, options: ToObjectOptions<S>) => any'.
Types of parameters 'options' and 'options' are incompatible.
Type 'ToObjectOptions<S>' is not assignable to type 'ToObjectOptions<PopulatedDoc<T, S>>'.
Types of property 'transform' are incompatible.
Type 'boolean | ((doc: S, ret: Record<string, any>, options: ToObjectOptions<S>) => any) | undefined' is not assignable to type 'boolean | ((doc: PopulatedDoc<T, S>, ret: Record<string, any>, options: ToObjectOptions<PopulatedDoc<T, S>>) => any) | undefined'.
Type '(doc: S, ret: Record<string, any>, options: ToObjectOptions<S>) => any' is not assignable to type 'boolean | ((doc: PopulatedDoc<T, S>, ret: Record<string, any>, options: ToObjectOptions<PopulatedDoc<T, S>>) => any) | undefined'.
Type '(doc: S, ret: Record<string, any>, options: ToObjectOptions<S>) => any' is not assignable to type '(doc: PopulatedDoc<T, S>, ret: Record<string, any>, options: ToObjectOptions<PopulatedDoc<T, S>>) => any'.
Types of parameters 'doc' and 'doc' are incompatible.
Type 'PopulatedDoc<T, S>' is not assignable to type 'S'.
'S' could be instantiated with an arbitrary type which could be unrelated to 'PopulatedDoc<T, S>'.
11 ): docs is mongoose.Types.Array<S> {
~~~~~~~~~~~~~~~~~~~~~~~
src/test.ts:8:32
8 export function isRefTypeArray<T, S extends mongoose.RefType>(
~
This type parameter might need an `extends S` constraint.
(the typescript suggestion of This type parameter might need an "extends S" constraint. is not a solution)
Steps to Reproduce
/* eslint-disable @typescript-eslint/ban-types */// NodeJS: 19.9.0// MongoDB: 5.0 (Docker)// Typescript 4.9.5import*asmongoosefrom'mongoose';// mongoose@7.2.2exportfunctionisRefTypeArray<T,Sextendsmongoose.RefType>(docs: mongoose.Types.Array<mongoose.PopulatedDoc<T,S>>|null|undefined// error on the next line): docs is mongoose.Types.Array<S>{returnArray.isArray(docs)&&docs.every((v)=>/* some testing func */true);}
Prerequisites
Mongoose version
7.2.2
Node.js version
20.2.0
MongoDB server version
unrelated
Typescript version (if applicable)
4.9.5
Description
mongoose 7.2.2 (via #13446) broke some types that are used in typegoose, but only typeguards that use
mongoose.Types.Array
fixes would be to either remove the following line, or remove the
<T>
from the linemongoose/types/types.d.ts
Line 45 in 6b820a7
both resolve the issue, i dont understand why typescript complains, but the mentioned solution(s) above resolve it for this case, but i dont know if this would break some types tests
full error (from the reproduce script):
(the typescript suggestion of
This type parameter might need an "extends S" constraint.
is not a solution)Steps to Reproduce
Reproduction Repository & Branch: https://github.com/typegoose/typegoose-testing/tree/mongooseToObjectOptions
Expected Behavior
no typescript error
The text was updated successfully, but these errors were encountered: