Typescript setup w/ Meteor 1.5

I followed the blog post but that didn’t work. Here’s my commit: https://github.com/Falieson/react15-meteor1.5/commit/b0c5ccd4f940d980a227789e151c9b1ffb8f71cf

Error

$ meteor
[[[[[ ~/Private/ReactMeteorExample ]]]]]

=> Started proxy.
client/index.tsx (2, 24): Cannot find module 'meteor/meteor'.
=> Started MongoDB.
=> Started your app.

Installed

$ meteor add barbatus:typescript
$ meteor npm install --save @types/meteor @types/react
  "compilerOptions": {
    "allowJs": false,
    "alwaysStrict": true,
    "jsx": "react",
    "module": "commonjs",
    "moduleResolution": "node",
    "noImplicitAny": false,
    "sourceMap": true,
    "strictNullChecks": false,
    "target": "es5",
    "types": [
      "meteor-typings"
    ]    

Additional question: should the typings be dev dependencies?

The "types" section in the tsconfig file should be unnecessary as you don’t have the meteor-typings directory (‘meteor-typings’ was an old way of doing things).

As the @types packages are only .d.ts files it shouldn’t matter whether they are standard or dev dependencies. Personally, I’d leave them as non-dev.

To fix the issue you’re getting, add a file at the top level called typings.d.ts and put in it a reference to the packages you want to reference, e.g.:

/// <reference types="@types/meteor" />

You may need to add the react types or they may get added automatically due to the jsx = react definition, but it seemed to run without any errors after I added the above.

The typescript docs suggest that the @types files should be included automatically, but I don’t know why they’re not. They weren’t picked up when I removed the “types” above.

An alternative solution is to specify the types explicitly in the tsconfig.json file e.g.:

    ...
    "target": "es5",
    "types": [ "meteor" ]

Here’s the relevant bit of the TS docs: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types

Thank you very much, i created the file and that fixed the error in my console!
If you want stack points I had made a duplicate of the question there: https://stackoverflow.com/questions/45442743/typescript-setup-w-meteor-1-5-cannot-find-module-meteor-meteor

Another question about the typings.d.ts file, you say they should “get added automatically”, so in your typings.d.ts file do you only have a reference for meteor? Or do you have

typings.d.ts

/// <reference types="@types/meteor" />
/// <reference types="@types/react" />
1 Like

Thanks, I answered the SO question too.

I downloaded your project, and found that I only needed to add the reference to @types/meteor, but as you fill the app out you may find you also need the @types/react at some point. For now, it doesn’t seem to be needed, and I even used VSCode and the React types/intellisense seemed to be fine.

Thanks - I guess I was hoping for a better understanding of when I would need the typings.d.ts file ? Seems like a last resort fallback when the automator doesn’t pickup?