Getting started with Typescript - default Meteor namespaces?

I have a weird issue adding typescript to an old Meteor 1.9 project.

Yesterday I did meteor add typescript, and started converting one .js file to .ts. This file has some references to HTTP.get, Meteor.settings, Meteor.users etc which are globals, not imported.

Yesterday VS Code automagically picked up the type definitions for these, e.g. it new that the 2nd parameter to HTTP.get should be of type HTTP.HTTPRequest. Brilliant!

Anyway, I committed my code to a branch, switched to another branch, then came back to it.

Now, VS Code isn’t picking up any of these global type definitions. The code I wrote yesterday is throwing up problems:

image

And yesterday the options.foo property was correctly red-underlined whereas now it isn’t.

I thought maybe I’d forgotten to add the tsconfig.json to my commit, so I went back to the main branch and started again with meteor add typescript, but it still doesn’t pick these up. It didn’t create a tscongif.json file for me so I don’t think I had one yesterday either.

I tried explicitly importing HTTP and Meteor but typescript can’t find those type definitions:

image

Any ideas how to get this working again?

I have no idea of typescript (yet), so my answer may be totally misguided, but if the problem is solely to put eslint at ease because of Meteor’s globals, I do this always by adding a line like this at the top of the module:

/* global HTTP */

Many of the Meteor packages are available through the @types/meteor package. Install that, and you should be good for most things.

meteor npm i -D @types/meteor
2 Likes

Brilliant, thanks @captainn, that sorted it!

I wonder why that happened automatically for me yesterday, but not when I did the same thing this morning. Weird.