TypeScript setup for Meteor

I’m still trying to improve my TypeScript setup for Meteor using zodern:types, but it’s still a mystery for me when Meteor actually finds the types for a package and when not.

Until recently, it was able to resolve most of the packages, but now it does not find the definitions for meteor/react-meteor-data anymore. I have no clue what caused this. I tried to add @types/meteor manually, but this made things even worse, so I removed it.

Also just recently, Meteor stopped recognizing the transform key in a find() / findAsync, so I have to cast the results to the actual model object now.

The issue might as well be related to a major update of WebStorm.

I attached my current config. If anyone has a clue why this does not work (anymore), I’d be super thankful. Adding types manually for things like useTracker() isn’t really fun.

{
  "compilerOptions": {
    /* Basic Options */
    "target": "es2018",
    "module": "esNext",
    "lib": ["esnext", "dom"],
    "allowJs": true,
    "checkJs": false,
    "jsx": "preserve",
    "incremental": true,
    "noEmit": true,

    /* Strict Type-Checking Options */
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,

    /* Additional Checks */
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": false,
    "noFallthroughCasesInSwitch": false,

    /* Module Resolution Options */
    "baseUrl": ".",
    "paths": {
      /* Support absolute /imports/* with a leading '/' */
      "/*": ["*"],
      "meteor/universe-i18n": ["node_modules/@types/meteor-universe-i18n/index.d.ts"],
      /* Pull in type declarations for Meteor packages from either zodern:types or @types/meteor packages */
      "meteor/*": ["node_modules/@types/meteor/*", ".meteor/local/types/packages.d.ts"]
    },
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "types": ["node", "mocha"],
    "esModuleInterop": true,
    "preserveSymlinks": true
  },
  "exclude": ["./.meteor/**", "./packages/**"],
  "include": ["./.meteor/local/types", "./**/*"]
}
1 Like

Known issue, I’m afraid, and so far very little appetite to fix the 5-6 issues that make typescript work out of the box for a new meteor project.
The solution is in this unmerged pr

2 Likes

Thanks for the hint, will try it!

This seems to have done the trick. And even the transform works now, amazing!

Thank you so much for your support!

One question: You removed this

node_modules/@types/meteor/

from meteor/*. So I guess the best way to resolve issues is to not reference the whole @types/meteor package folder here but instead select sub-packages, correct?

I am also wondering: Why is the official Readme referencing the @types/meteor package folder, but does not mention that one should add the package itself? Is it recommended to install it manually or not? I had issues after doing so. But now, it only worked after I did install it. Seems to confirm my assumption. If this is correct, I think the Readme should mention this as well (as a peer dependency).

Ah, and another question in this context: I used to get a TypeScript error when I did not import Meteor, Mongo or check, but this does not work anymore since a while (i.e. even before the change). TypeScript now recognizes these as globals. I’d rather prefer to import them manually. Is there a way to get the warnings back?

Now and then, I have an issue with TS in Meteor and I wish we had an easy way Maybe this feature could solve it [Feature]: Moving zodern:types to core · Issue #12509 · meteor/meteor · GitHub

Sorry for the small rant hehe

Rave you ran meteor lint(to run the type thingy) on the project?

1 Like


This feature is bad. It took me some time to see what it is. :joy:

Of course, zodern is not to blame for this.

I am wondering why exactly Meteor is still using its own import syntax in the first place? I know that it is due to its own package management, which has to support isomorphism as well (for mobile devices), but wouldn’t there be a way to achieve the same with another bundler nowadays?

Not a huge fan of rollup and webpack, though, as things can get pretty complicated with them as well. Vite is a bit better, I guess. Maybe it’s too hard to get to the same level of “simplicity” with one of these?

2 Likes

In the ideal world, you would not need to bring in the meteor types from DefinitelyTyped (node_modules/@types/meteor) but instead only use the ones made available via packages themselves and unpacked by zodern:types

example

Unfortunately, there are some remaining cases where you need to still rely on @types/meteor:

So what the example tsconfig does is to cherrypick types from the definitelytyped ones and then use ./.meteor/local/types/packages.d.ts (generated by zodern:types) for all other meteor/* packages.

1 Like