This project is read-only.

Backbone.View definition

Topics: General
Feb 5, 2013 at 4:05 AM
Edited Feb 5, 2013 at 5: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 4:09 AM
If it's not supported yet, this is the syntax I would suggest for it:
       model: <Model>;
Feb 5, 2013 at 4:26 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Feb 7, 2013 at 12:36 AM
Edited Feb 7, 2013 at 12:37 AM
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 9:35 AM
@omidkrad, Generics look set to be introduced in version 0.9.x. Please refer to the roadmap.
Aug 7, 2013 at 12:25 AM
Edited Apr 12, 2014 at 1:25 AM
Maybe the solution for this is the new typeof operator?

Related work item: