Set more specific types for Backbone Model and Collection url properties. (#20568)

This commit is contained in:
Randy Patterson Jr
2017-10-23 08:01:36 -07:00
committed by Andy
parent 639f1b19ea
commit f91a1fa80d
2 changed files with 17 additions and 1 deletions
+2
View File
@@ -115,6 +115,8 @@ class Employee extends Backbone.Model {
super(options);
this.reports = new EmployeeCollection();
this.reports.url = '../api/employees/' + this.id + '/reports';
// Test that collection url property can be set as a function returning a string.
this.reports.url = () => { return ""; };
}
more() {
+15 -1
View File
@@ -100,7 +100,6 @@ declare namespace Backbone {
}
class ModelBase extends Events {
url: any;
parse(response: any, options?: any): any;
toJSON(options?: any): any;
sync(...arg: any[]): JQueryXHR;
@@ -133,6 +132,13 @@ declare namespace Backbone {
id: any;
idAttribute: string;
validationError: any;
/**
* Returns the relative URL where the model's resource would be located on the server.
* @memberof Model
*/
url: () => string;
urlRoot: any;
constructor(attributes?: any, options?: any);
@@ -314,6 +320,14 @@ declare namespace Backbone {
take(): TModel;
take(n: number): TModel[];
toArray(): TModel[];
/**
* Sets the url property (or function) on a collection to reference its location on the server.
*
* @memberof Collection
*/
url: string | (() => string);
without(...values: TModel[]): TModel[];
}