Wait hang on, that's a super specific solution (as mentioned by @DanielRosenwasser on the PR…)
How would this solve the issue with typeof
of generic classes, brought up by @ericeslinger and @Saviio and myself. This has the same root cause but is not solved by this fix:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | /** A generic UI component that renders to a DOM element */ abstract class UIComponent<RenderedElementT extends HTMLElement> { public static staticMethod() { /* ... */ } // more static methods here ... public abstract render(): RenderedElementT; // ... } class TextField extends UIComponent<HTMLInputElement> { public render() { return document.createElement("input") } // ... } function findComponentsByType(ComponentClass: typeof UIComponent) { // THIS:::: // The issue here is that e.g. TextField is not assignable to `typeof UIComponent` // but then how do we make sure that only a "component class" can be passed in? // other than having to resort to a "class object" interface type that includes // a constructor and all static methods, which needs to be declared separately } var results = findComponentsByType(TextField); |
Or do we open up another issue for this / is there another issue open to track this?
from: https://github.com/Microsoft/TypeScript/issues/16985#issuecomment-318525108