Skip to content

Need to support declaration merging in external modules #2821

Description

@cnshenj

jQuery (jQuery UI) support method extensions. If we write my own jQuery UI widget, I can do this:
In myWidget.ts:

interface JQuery {
    myWidget(): JQuery
}

class myWidget {
    public foo() {
        // This is okay now, but will fail once we add some import statements to this file,
        // because TypeScript thinks this JQuery is not that JQuery
        var some: JQuery = $("#some-id").text();
    }
}

$.fn.extend({
    myWidget() {...}
});

Then in another file:

$(selector).myWidget(); // Create a new myWidget, this is okay because of myWidget() is declared in my version of JQuery interface
$(selector).attr("id", "my-id"); // This is okay because attr is declared in jquery.d.ts

However, this stops working when I add this line to myWidget.ts:

import helpers = require("helpers");

Now TypeScript thinks there 2 JQuery interfaces, instead of merging them into one. How do I tell TypeScript that I'm not creating a new interface for this module, but need to merge it with an existing interface?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions