Migrating to Typescript - couple of questions

Preface - I’m a Typescript noob -read a bunch of documentation and done some tutorials and only just in the process of migrating a project over, file by file. So feel free to point me to any other resources if the questions below are too basic to answer, although their Meteor specific nature makes it difficult to find specific answers to them.

Funnily enough, both these questions relate to Meteor.users collection…

  1. Our Meteor users collection has extra properties beyond the standard ones created by Meteor. When searching through the Meteor Users collection, we obviously use those properties, however typescript throws warning when writing the code to do so (which makes sense, because as far as Typescript is concerned, the returned User documents don’t have those extra properties): Property 'customPropertyName' does not exist on type 'User'.


How do we solve this? Do we monkey-patch the Meteor typings? Is there another Typescript way to handle such a situation?

  1. On a different file, I am weirdly getting a typescript warning: Property 'users' does not exist on type 'typeof Meteor'. This is extra weird, because the query Meteor.users.findOne... is identical in the file for question 1

Any idea what/why this would happen?

Update on question 2, adding a Meteor import explicitly fixes things:

import { Meteor } from 'meteor/meteor';

Possibly the best solution to 1? Using type assertions. For example:

const user = Meteor.users.findOne(userId); // user is implicitly typed as Meteor.User or undefined
const { prop1, prop2 } = user as MyAppUser; // MyAppUser is a custom type specific to the application
1 Like