generics - TypeScript compiler confused with large inheritance/extension chain -
i have following (reasonably complex) extension chain. minimal reproducible example of problem (obviously classes have behavioural implementations in application).
export class basemodel { public somebasemodelmethod(): void { } } export class baseview { public somebaseviewmethod(): void { } } export class collectionview<tchildview extends baseview, tmodel extends basemodel> extends baseview { public somecollectionviewmethod(): void { } } export class itemview<tmodel extends basemodel> extends baseview { public setitem(model: tmodel): void { } } export interface igridview<tchildview extends itemview<tmodel>, tmodel extends basemodel> extends collectionview<tchildview, tmodel> { somegridviewmethod(): void; } export class gridview<tchildview extends itemview<tmodel>, tmodel extends basemodel> extends collectionview<tchildview, tmodel> implements igridview<tchildview, tmodel> { public somegridviewmethod(): void { } } function bind<tinterface>(key: string, implementation: new (...args: any[]) => tinterface) { // bindings here } bind<igridview<itemview<basemodel>, basemodel>>("igridview", gridview);
when compile, error on gridview
part of final line (the bind
statement). error follows:
ts2345 argument of type 'typeof gridview' not assignable parameter of type 'new (...args: any[]) => igridview<itemview<basemodel>, basemodel>'. type 'collectionview<any, any>' not assignable type 'igridview<itemview<basemodel>, basemodel>'. property 'somegridviewmethod' missing in type 'collectionview<any, any>'.
as can see, expecting somegridviewmethod
on collectionview
. however, gridview
extends collectionview
, why expecting find gridview
methods on collectionview
class?
the code compiles correctly in 2.0.3
, not in 1.8.10
.
this compiles fine in both 1.8.x
, 2.x
:
type typedgridview = { new (...args: any[]): igridview<itemview<basemodel>, basemodel> }; function bind<tinterface>(key: string, implementation: new (...args: any[]) => tinterface) { // bindings here } bind("igridview", gridview typedgridview);
it seems 1.8.x
compiler fails recognize gridview
constructor to:
igridview<itemview<basemodel>, basemodel>
Comments
Post a Comment