Argument of type ‘{ hint: string; }’ is not assignable to parameter of type ‘Options’.
Object literal may only specify known properties, and ‘hint’ does not exist in type ‘Options’.
It works but I think there would be a better way to define types.
How do you define Meteor.users type?
That’s weird. As I look at it now, it should work, as find wants anything that extendsOptions<T> (source), and Meteor.users is a normal Mongo.Collection (source). I’ll check it later.
Yes, that’s weird.
On VSCode, when I hover the Users.find function I have this:
(method) Mongo.Collection<UserType, UserType>.find<Mongo.Options<UserType>>(selector?: string | Mongo.ObjectID | Mongo.Selector<UserType> | undefined, options?: Mongo.Options<UserType> | undefined): Mongo.Cursor<...> (+1 overload)
Find the documents in a collection that match the selector.
But when I hover the UsersActivities.find function, I have this:
(method) Mongo.Collection<ActivityType, ActivityType>.find<{
sort: {
createdAt: number;
};
limit: number;
hint: string;
}>(selector?: string | Mongo.ObjectID | Mongo.Selector<ActivityType> | undefined, options?: {
sort: {
createdAt: number;
};
limit: number;
hint: string;
} | undefined): Mongo.Cursor<...> (+1 overload)
Find the documents in a collection that match the selector.
type UserType = Meteor.User & { foo?: string };
const Users: Mongo.Collection<UserType> = Meteor.users;
// Both OK.
Meteor.users.find();
Users.find();
// Both OK.
Meteor.users.find({ _id: '' });
Users.find({ _id: '' });
// Both fail.
Meteor.users.find({ _id: '' }, { hint: '' });
Users.find({ _id: '' }, { hint: '' });
// Both OK.
Meteor.users.find({ _id: '' }, { hint: '', limit: 50 });
Users.find({ _id: '' }, { hint: '', limit: 50 });
The reason is, that the options are expected to extend the Options<T> type. This type has only optional properties, but due to the way how TypeScript work, { hint: string } is not considered to be extending Options<T>. By adding { limit: number } everything works, as then it’s Options<T> & { hint: string }.
The first step would be to add hint to Options<T> with a proper comment. Here I strongly encourage you to file a PR.
The second step would be to change the Options<T> type in a way that only the transform property would be parametrized. Here I believe it’s not as trivial and will take more time.
@radekmie Wow, that’s complicated. I confirm that by adding limit or other fields in Options<T> it solve the issue. Thank you very much.
I created a pull request but without additional test. It works on my local. PR