-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Intersection type containing a constructor function type should count as one #10261
Comments
Is there a real world scenario that needs this? |
I was playing around with mixins, which involve intersecting class types. It would take more than just this to make those work, though! interface MixinStatics {
mixinStatic(): void;
}
interface MixinInstance {
mixinInstance(): void;
}
function mixin<Instance, Cls extends { new(): Instance }>(cls: Cls): { new(): Instance & MixinInstance } & MixinStatics & Cls {
return <any> class extends cls {
static mixinStatic() {}
mixinInstance() {}
}
}
class Super {}
// Type annotation hopefully not necessary
class C extends mixin<Super, typeof Super>(Super) { }
C.mixinStatic();
new C().mixinInstance(); |
One real world scenario is mixin http://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/. If counting intersection type with construct signature would at least partially solve the long awaited mixin support in TypeScript. |
Just got here with exactly same issue. Mixins are very important, so far possible with ES6, so would be great if we could actually do that in TS. |
Seems quite handy in ES6 const Storage = Sup => class extends Sup {
save(database) { }
};
const Validation = Sup => class extends Sup {
validate(schema) { }
};
class Person { }
class Employee extends Storage(Validation(Person)) { } |
Duplicate of #4890? |
TypeScript Version: nightly
Code
Expected behavior:
No error.
Actual behavior:
The text was updated successfully, but these errors were encountered: