atom-typescript: Can't find proper default variable export syntax

Since the update from 1.10 to 2.6 (just after the switch to TypeScript 1.5) every d.ts file needs to have a default export. I haven’t read the ES6 spec, but I assume all modules have to have a default export now.

This is all well and good when exporting my own classes, but when using 3rd party libraries, this becomes difficult. Here is a snippet of JQuery d.ts code.

declare var $: JQueryStatic;
declare module "jquery" {
    export = $;
}

Before the update, this code worked just fine and didn’t produce any issues, but now I need a default export. The only syntactically correct way that I got to work was the following:

declare var $: JQueryStatic;
declare module "jquery" {
    export default $;
}

This produces incorrect code output:

// FROM
import $ from 'jquery';
var obj = $(ev.srcElement)

// TO
var jquery_1 = require('jquery');
var obj = jquery_1.default(ev.srcElement)

Clearly jQuery does not have a static default method, but even if it did, this is clearly not the expected behavior. Not to mention the $ was not preserved at all. Please let me know how I can declare a default export variable. I have done about an hour of searching for this syntax and cannot find it. Or perhaps I’m going about it the wrong way?

Anyway, thanks in advance.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

In the long ticket about ES modules in the TypeScript repository, the gist is here: https://github.com/Microsoft/TypeScript/issues/2242#issuecomment-83694181

You can’t use the ES6 import syntax to import legacy AMD/CJS module defaults, you must continue to use the import $ = require('jquery'); syntax. import foo from 'foo' will work only for ES6 default exports because they don’t work the same (in ES6 it’s just syntactic sugar for referencing the default property of the imported module).