mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-15 01:32:56 +08:00
[backbone.marionette] Added parameter for model to childview function of CollectionView (#27441)
* Added model param to childview function of CollectionView * Added private property to MyOtherView to ensure type difference
This commit is contained in:
@@ -135,6 +135,15 @@ class MyView extends Marionette.View<MyModel> {
|
||||
}
|
||||
}
|
||||
|
||||
class MyOtherView extends MyView {
|
||||
private readonly foo: string;
|
||||
|
||||
constructor(model: MyModel) {
|
||||
super(model);
|
||||
this.foo = 'bar';
|
||||
}
|
||||
}
|
||||
|
||||
class MainRegion extends Marionette.Region {
|
||||
constructor() {
|
||||
super();
|
||||
@@ -185,10 +194,20 @@ class MyHtmlElRegion extends Marionette.Region {
|
||||
}
|
||||
}
|
||||
|
||||
class MyCollectionView extends Marionette.CollectionView<MyModel, MyView> {
|
||||
class MyCollectionView extends Marionette.CollectionView<MyModel, MyView | MyOtherView> {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.childView = (model: MyModel) => {
|
||||
if (model.get('isFoo')) {
|
||||
return MyView;
|
||||
}
|
||||
|
||||
return MyOtherView;
|
||||
};
|
||||
|
||||
this.childView = MyView;
|
||||
|
||||
this.childViewEvents = {
|
||||
render() {
|
||||
console.log('a childView has been rendered');
|
||||
@@ -282,7 +301,7 @@ function CollectionViewTests() {
|
||||
cv.collection.add(new MyModel());
|
||||
app.mainRegion.show(cv);
|
||||
cv.emptyView = MyView;
|
||||
const view: Marionette.CollectionView<MyModel, MyView> = cv.destroy();
|
||||
const view: Marionette.CollectionView<MyModel, MyView | MyOtherView> = cv.destroy();
|
||||
}
|
||||
|
||||
class MyController {
|
||||
|
||||
7
types/backbone.marionette/index.d.ts
vendored
7
types/backbone.marionette/index.d.ts
vendored
@@ -3,7 +3,8 @@
|
||||
// Definitions by: Zeeshan Hamid <https://github.com/zhamid>,
|
||||
// Natan Vivo <https://github.com/nvivo>,
|
||||
// Sven Tschui <https://github.com/sventschui>,
|
||||
// Volker Nauruhn <https://github.com/razorness>
|
||||
// Volker Nauruhn <https://github.com/razorness>,
|
||||
// Ard Timmerman <https://github.com/confususs>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
@@ -1157,7 +1158,7 @@ export interface CollectionViewOptions<
|
||||
/**
|
||||
* Specify a child view to use.
|
||||
*/
|
||||
childView?: (() => typeof Backbone.View) | typeof Backbone.View;
|
||||
childView?: ((model: TModel) => typeof Backbone.View) | typeof Backbone.View;
|
||||
|
||||
/**
|
||||
* Define options to pass to the childView constructor.
|
||||
@@ -1219,7 +1220,7 @@ export class CollectionView<TModel extends Backbone.Model, TView extends View<TM
|
||||
/**
|
||||
* Specify a child view to use.
|
||||
*/
|
||||
childView: (() => { new(...args: any[]): TView }) | { new(...args: any[]): TView };
|
||||
childView: ((model: TModel) => { new(...args: any[]): TView }) | { new(...args: any[]): TView };
|
||||
|
||||
/**
|
||||
* Define options to pass to the childView constructor.
|
||||
|
||||
Reference in New Issue
Block a user