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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -