mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 19:07:08 +00:00
Set defaults for the type parameters of generic types in backbone (#34875)
* Give defaults to the generic type parameters * Satisfy the linter * Re-enable the npm-naming linter rule for backbone * Add tests for the new feature in backbone
This commit is contained in:
parent
7c77a9c53a
commit
ed6cd87f64
@ -196,6 +196,8 @@ class Library extends Backbone.Collection<Book> {
|
||||
|
||||
class Books extends Backbone.Collection<Book> { }
|
||||
|
||||
class ArbitraryCollection extends Backbone.Collection { }
|
||||
|
||||
function test_collection() {
|
||||
|
||||
var books = new Books();
|
||||
@ -483,3 +485,27 @@ namespace v1Changes {
|
||||
Backbone.sync('read', new EmployeeCollection());
|
||||
}
|
||||
}
|
||||
|
||||
interface BookViewOptions extends Backbone.ViewOptions<Book> {
|
||||
featured: boolean;
|
||||
}
|
||||
|
||||
class BookView extends Backbone.View<Book> {
|
||||
featured: boolean;
|
||||
constructor(options: BookViewOptions) {
|
||||
super(options);
|
||||
this.featured = !!options.featured;
|
||||
}
|
||||
}
|
||||
|
||||
interface ModellessViewOptions extends Backbone.ViewOptions {
|
||||
color?: string;
|
||||
}
|
||||
|
||||
class ModellessView extends Backbone.View {
|
||||
color: string;
|
||||
constructor(options: ModellessViewOptions) {
|
||||
super(options);
|
||||
this.color = options.color;
|
||||
}
|
||||
}
|
||||
|
||||
8
types/backbone/index.d.ts
vendored
8
types/backbone/index.d.ts
vendored
@ -300,7 +300,7 @@ declare namespace Backbone {
|
||||
matches(attrs: any): boolean;
|
||||
}
|
||||
|
||||
class Collection<TModel extends Model> extends ModelBase implements Events {
|
||||
class Collection<TModel extends Model = Model> extends ModelBase implements Events {
|
||||
|
||||
/**
|
||||
* Do not use, prefer TypeScript's extend functionality.
|
||||
@ -492,7 +492,7 @@ declare namespace Backbone {
|
||||
private _updateHash(location: Location, fragment: string, replace: boolean): void;
|
||||
}
|
||||
|
||||
interface ViewOptions<TModel extends Model> {
|
||||
interface ViewOptions<TModel extends Model = Model> {
|
||||
model?: TModel;
|
||||
// TODO: quickfix, this can't be fixed easy. The collection does not need to have the same model as the parent view.
|
||||
collection?: Backbone.Collection<any>; //was: Collection<TModel>;
|
||||
@ -504,7 +504,7 @@ declare namespace Backbone {
|
||||
attributes?: {[id: string]: any};
|
||||
}
|
||||
|
||||
class View<TModel extends Model> extends EventsMixin implements Events {
|
||||
class View<TModel extends Model = Model> extends EventsMixin implements Events {
|
||||
|
||||
/**
|
||||
* Do not use, prefer TypeScript's extend functionality.
|
||||
@ -547,7 +547,7 @@ declare namespace Backbone {
|
||||
}
|
||||
|
||||
// SYNC
|
||||
function sync(method: string, model: Model | Collection<Model>, options?: JQueryAjaxSettings): any;
|
||||
function sync(method: string, model: Model | Collection, options?: JQueryAjaxSettings): any;
|
||||
function ajax(options?: JQueryAjaxSettings): JQueryXHR;
|
||||
var emulateHTTP: boolean;
|
||||
var emulateJSON: boolean;
|
||||
|
||||
@ -8,7 +8,6 @@
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"npm-naming": false,
|
||||
"export-just-namespace": false,
|
||||
"interface-name": false,
|
||||
"jsdoc-format": false,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user