Microsoft/TypeScript

Allow a module to implement an interface

Open

#420 opened on Aug 10, 2014

 (66 comments) (115 reactions) (0 assignees)TypeScript (13,395 forks)batch import
Help WantedSuggestion

Repository metrics

Stars
 (108,860 stars)
PR merge metrics
 (PR metrics pending)

Description

It would be useful when a module can implement an interface using the implements keyword. Syntax: module MyModule implements MyInterface { ... }.

Example:

interface Showable {
    show(): void;
}
function addShowable(showable: Showable) {

}

// This works:
module Login {
    export function show() {
        document.getElementById('login').style.display = 'block';
    }
}
addShowable(Login);

// This doesn't work (yet?)
module Menu implements Showable {
    export function show() {
        document.getElementById('menu').style.display = 'block';
    }
}
addShowable(Menu);

Contributor guide