Follow @Duncan's @Bartvds's answer, here to provide a workable way after years passed.
At this point after Typescript 1.5 released (@Jun 15 '15), your helpful interface
interface MyType {
instanceMethod();
}
interface MyTypeStatic {
new():MyType;
staticMethod();
}
can be implemented this way with the help of decorator.
/* class decorator */
function staticImplements<T>() {
return <U extends T>(constructor: U) => {constructor};
}
@staticImplements<MyTypeStatic>() /* this statement implements both normal interface & static interface */
class MyTypeClass { /* implements MyType { */ /* so this become optional not required */
public static staticMethod() {}
instanceMethod() {}
}
Refer to my comment at github issue 13462.
visual result:
Compile error with a hint of static method missing.
After static method implemented, hint for method missing.
Compilation passed after both static interface and normal interface fulfilled.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…