You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems that polymorphic 'this' types don't apply as expected to intersection and union types.
Motivating Example: Lightweight Mixins
This example was forked from the proposal on polymorphic 'this' types considering "lightweight mixin"s. Unfortunately, the model can only be extended once because 'this' only includes "real" class extensions and no union type extensions as shown in the example. That's why the current implementation doesn't help us with the specified example.
interfaceModel{extend<T>(t: T): this &T;}interfaceNamedModelextendsModel{name: string;}declarefunctioncreateNamedModel(): NamedModel;varextendedModel=createNamedModel().extend({age: 30}).extend({job: "programmer"});extendedModel.name;// validextendedModel.job;// validextendedModel.age;// error: Property 'age' does not exist because type is NamedModel & { job: string }
This would require to assign intersection and union types to "this" instead of only superclasses of A. As far as I can see, this should not be too complicated/invasive, is it? I could not find any explicit decision against this feature, so maybe it's kind of a bug?
The text was updated successfully, but these errors were encountered:
TypeScript Version: 1.8.0
It seems that polymorphic 'this' types don't apply as expected to intersection and union types.
Motivating Example: Lightweight Mixins
This example was forked from the proposal on polymorphic 'this' types considering "lightweight mixin"s. Unfortunately, the model can only be extended once because 'this' only includes "real" class extensions and no union type extensions as shown in the example. That's why the current implementation doesn't help us with the specified example.
Suggestion
I suggest allowing the following:
This would require to assign intersection and union types to "this" instead of only superclasses of A. As far as I can see, this should not be too complicated/invasive, is it? I could not find any explicit decision against this feature, so maybe it's kind of a bug?
The text was updated successfully, but these errors were encountered: