mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-03-29 08:58:23 +08:00
Merge pull request #6401 from Spinarooni/backbone-comparator-issue#6394
Update Backbone collection.comparator definition to accpet string and…
This commit is contained in:
@@ -41,7 +41,7 @@ namespace Backbone.Associations.Tests {
|
||||
}
|
||||
|
||||
class Locations extends Backbone.Collection<Location> {
|
||||
comparator(c: Backbone.Model) {
|
||||
comparator = (c: Backbone.Model) => {
|
||||
return c.get("Number");
|
||||
}
|
||||
}
|
||||
|
||||
6
backbone/backbone-global.d.ts
vendored
6
backbone/backbone-global.d.ts
vendored
@@ -192,8 +192,10 @@ declare namespace Backbone {
|
||||
|
||||
fetch(options?: CollectionFetchOptions): JQueryXHR;
|
||||
|
||||
comparator(element: TModel): number;
|
||||
comparator(compare: TModel, to?: TModel): number;
|
||||
/**
|
||||
* Specify a model attribute name (string) or function that will be used to sort the collection.
|
||||
*/
|
||||
comparator: string | ((element: TModel) => number | string) | ((compare: TModel, to?: TModel) => number);
|
||||
|
||||
add(model: {}|TModel, options?: AddOptions): TModel;
|
||||
add(models: ({}|TModel)[], options?: AddOptions): TModel[];
|
||||
|
||||
@@ -120,6 +120,16 @@ class Library extends Backbone.Collection<Book> {
|
||||
// This model definition is here only to test type compatibility of the model, but it
|
||||
// is not necessary in working code as it is automatically inferred through generics.
|
||||
model: typeof Book;
|
||||
|
||||
constructor(models?: Book[] | Object[], options?: any) {
|
||||
super(models, options);
|
||||
|
||||
// Test comparator allowed types.
|
||||
this.comparator = "title";
|
||||
this.comparator = (model: Book) => { return 1; };
|
||||
this.comparator = (model: Book) => { return "Title"; };
|
||||
this.comparator = (model1: Book, model2: Book) => { return 1; };
|
||||
}
|
||||
}
|
||||
|
||||
class Books extends Backbone.Collection<Book> { }
|
||||
|
||||
Reference in New Issue
Block a user