Reputation: 2556
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
tsconfig.json
"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?
Upvotes: 0
Views: 769
Reputation: 4122
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
This section starts by saying 'By default all visible “@types” packages are included in your compilation.' but goes on to explain how "typeRoots" and "types" can be configured in the tsconfig.json
file.
Upvotes: 3