backbone.js - TypeScript generics shows in intellisense but does not compile -
i'm trying use generics in backbone typescript definition. why following code not work?! try in playground.
declare module backbone { class model{} interface viewoptions<tmodel extends model> { model?: tmodel; } class view<tmodel extends model> { constructor(options?: viewoptions<tmodel>); model: tmodel; } } class mymodel extends backbone.model { } class myview extends backbone.view<mymodel> { } // error: not select overload 'new'' expression. var myview = new myview({ model: new mymodel(), num: 1 }); // in typescript playground when hover on 'model' in // previous line correctly shows type 'mymodel' var model = myview.model; // expected of type mymodel
update:
i figured compiler pass if explicitly set constructor myview
:
class myview extends backbone.view<mymodel> { constructor(options?: backbone.viewoptions<mymodel>) { super(); } }
but use of generics?! defect in compiler?!
if not specify constructor compiler expects tmodel
, not mymodel
trying pass in. seems compiler bug understanding of generics correct.
additionally sure pass on parameter super class :
class myview extends backbone.view<mymodel> { constructor(options?: backbone.viewoptions<mymodel>) { super(options); // pass on } }
Comments
Post a Comment