[1.8.2] typescript - import from meteor packages

Just trying out typescript support 1.8.2

It compiles fine but complains that importing from meteor/etc that the package isn’t found.

When I was using flow there was a way to map things so it would find the packages properly.

I was able to use the paths configuration in tsconfig.json but TypeScript doesn’t understand the format of Meteor’s exports.

For meteor/meteor I was able to install npm @types/meteor

For other community packages… my thoughts on autogeneration…

Meteor generates something in the format:

Package._define("dburles:factory", {
  Factory: Factory
});

Would be really cool if we could generate some stub .d files for TypeScript usage that would at least let us validate if exports are valid or not…

1 Like

At the project I’m working for we started to add *.d.ts for the missing packages. Some of them are handmade and some were taken from github comments/gists and amended to work for us. The best option would be to publish them to DefinitelyTyped but I’m sure if that would work since these are not npm packages per se.

Regarding the problems you’re having with the format of meteor exports. Here’s an example of a crude definition for edgee:slingshot:

declare module 'meteor/edgee:slingshot' {
  export namespace Slingshot {
    export class Upload {
      constructor(uploadType: string);

      send(file: File, callback: (error?: Error, url?: string) => void): void;
      progress(): number;
      xhr: XMLHttpRequest;
    }
  }
}

Or the problem you’re having is that dburles:factory defines a global object?

1 Like