// TODO: Why does the compiler not complain when Marionette is missing?
import * as Marionette from "backbone.marionette"
import TodoCollection from "./TodoCollection"
import TodoModel from "./TodoModel"
import TodoView from "./TodoView"

// Add childViewContainer?:string; to CollectionViewOptions in marionette/index.d.ts.

interface TodosViewOptions extends Marionette.CollectionViewOptions<TodoModel> {
  collection: TodoCollection
}

export default class TodosView extends Marionette.CompositeView<TodoModel, TodoView> {
  constructor(options: TodosViewOptions) {
    super({
      childViewContainer: ".js-child-view-container"
    })

    this.collection = options.collection
  }

  childView = TodoView

  collection: TodoCollection

  template = require("./TodosView.ejs")
}

// TODO: Why does the compiler not complain when Marionette is missing?
import * as Marionette from "backbone.marionette"
import TodoCollection from "./TodoCollection"
import TodoModel from "./TodoModel"
import TodoView from "./TodoView"

// Add this to marionette/index.d.ts.
// interface CompositeViewOptions<TModel extends Backbone.Model> extends CollectionViewOptions<TModel> {
//     childView?: string,
//     collection?: Backbone.Collection<TModel>,
//     template?: any
// }

interface TodosViewOptions extends Marionette.CompositeViewOptions<TodoModel> {
  collection: TodoCollection
}

export default class TodosView extends Marionette.CompositeView<TodoModel, TodoView> {
  constructor(options: TodosViewOptions) {
    super(TodosView.setDefaultOptions(options))
  }

  childView = TodoView

  collection: TodoCollection

  template = require("./TodosView.ejs")

  private static setDefaultOptions(options: TodosViewOptions): TodosViewOptions {
    options.childViewContainer = ".js-child-view-container"
    return options
  }
}

Introduce setDefaultOptions to extend the options
Introduce setDefaultOptions to extend the options
