Make it possible to initialize a Backbone.Collection from raw objects

The following syntax is supported in Backbone, but is currently not compileable in Typescript:

    var data = [
      { id: 1, bar: 'foo' },
      { id: 2, bar: 'baz' }
    ];

    var myCollection = new Backbone.Collection(data);

As of now, the constructor expects an array of models. I've added the Object[] parameter type, in addition to the TModel[] type to support this syntax.
This commit is contained in:
Frederik Wordenskjold
2015-07-15 16:20:54 +02:00
parent 0fff32b558
commit ea103215ea
+2 -2
View File
@@ -173,8 +173,8 @@ declare module Backbone {
models: TModel[];
length: number;
constructor(models?: TModel[], options?: any);
initialize(models?: TModel[], options?: any): void;
constructor(models?: TModel[] | Object[], options?: any);
initialize(models?: TModel[] | Object[], options?: any): void;
fetch(options?: CollectionFetchOptions): JQueryXHR;