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
import type { MongoQuery } from '@ucast/mongo2js';
import type { Types as MongooseTypes } from 'mongoose';
export type Id = MongooseTypes.ObjectId;
interface User {
// ....
readonly globalRoleIds: readonly Id[];
}
// ....
const mongoQuery: MongoQuery<User> = {
globalRoleIds: {
$in: [adminRole._id],
},
};
I've got :
Type '{ $in: Types.ObjectId[]; }' is not assignable to type '(MongoQueryFieldOperators<User> & MongoQueryTopLevelOperators<User>) | OperatorValues<readonly ObjectId[]> | undefined'.
Types of property '$in' are incompatible.
Type 'ObjectId[]' is not assignable to type '(readonly ObjectId[])[] | User[] | undefined'.
Type 'ObjectId[]' is not assignable to type '(readonly ObjectId[])[]'.
Type 'ObjectId' is missing the following properties from type 'readonly ObjectId[]': length, concat, join, slice, and 26 more.ts(2322)
user.entity.ts(62, 12): The expected type comes from property 'globalRoleIds' which is declared here on type 'Query<User, MongoQueryFieldOperators<User> & MongoQueryTopLevelOperators<User>> & MongoQueryTopLevelOperators<...>'
This error is because globalRoleIds is a list of ids.
So i have to cast my query by doing as unknown as MongoQuery<User>; which limits interest of query type.
Do you have a better alternative ?
Thank you
The text was updated successfully, but these errors were encountered:
Hi!
If I write :
I've got :
This error is because
globalRoleIds
is a list of ids.So i have to cast my query by doing
as unknown as MongoQuery<User>;
which limits interest of query type.Do you have a better alternative ?
Thank you
The text was updated successfully, but these errors were encountered: