Happy1234
Happy1234

Reputation: 729

How to set the type of the collection in typescript and meteor.js?

I’m really new to typescript and wonder how to set a type to a collection.

This is my part of the react component. I need to pull a user document from Users collection.

const user = useTracker(() => Users.find({_id: userId}).fetch(), [userId]);

I have a Cannot find name 'Users'. Did you mean 'user'? error on my code editor.

I didn’t not mean to type user, the collection name is the Users.

The thing is the Users collection file is written in js not tsx.

Is there a way to define a type of the Users collection?

Upvotes: 0

Views: 124

Answers (1)

Minh Nguyen
Minh Nguyen

Reputation: 490

I use this method:

import { Meteor } from "meteor/meteor";
import { Mongo } from "meteor/mongo";
import { UserType } from "/imports/types/users";

const Users: Mongo.Collection<UserType> = Meteor.users;

export default Users;

Upvotes: 3

Related Questions