Backbone.View definition

Topics: General
Feb 5, 2013 at 3:05 AM
Edited Feb 5, 2013 at 4:48 PM
The definition of Backbone.View in todos.ts sample is as follows:
   export class View {
       constructor (options? );
       $(selector: string): any;
       el: HTMLElement;
       $el: any;
       model: Model;
       remove(): void;
       delegateEvents: any;
       make(tagName: string, attrs? , opts? ): View;
       setElement(element: HTMLElement, delegate?: bool): void;
       tagName: string;
       events: any;

       static extend: any;
   }
model is set to be of type Backbone.Model however, in Backbone.js the 'class type' extending Backbone.Model is assigned to the model property and not an instance of Backbone.Model. Backbone will take care of the instantiation of the type. So I guess the correct definition should be something like:
       model: ()=>Model;
but that still creates compiler error. How is it possible to define this?
       model: class A where A extends Backbone.Model; // generics?
Feb 5, 2013 at 3:09 AM
If it's not supported yet, this is the syntax I would suggest for it:
       model: <Model>;
Coordinator
Feb 5, 2013 at 3:26 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Feb 6, 2013 at 11:36 PM
Edited Feb 6, 2013 at 11:37 PM
Well, the work item was closed but this question is not answered yet and I think it's a common issue that should be addressed in the specifications.
Feb 7, 2013 at 8:35 AM
@omidkrad, Generics look set to be introduced in version 0.9.x. Please refer to the roadmap.
Aug 6, 2013 at 11:25 PM
Edited Apr 12, 2014 at 12:25 AM
Maybe the solution for this is the new typeof operator?

Related work item: https://typescript.codeplex.com/workitem/2425