MithrilJS / mithril.js

A JavaScript Framework for Building Brilliant Applications
https://mithril.js.org
MIT License
13.99k stars 926 forks source link

The controller method is declared as required in mithril.d.ts #1336

Closed andraaspar closed 7 years ago

andraaspar commented 8 years ago

Description:

mithril.d.ts declares the controller method as required, whereas the documentation says it is optional. This causes components written in TypeScript to always require a controller.

Expected:

    interface Component<T extends Controller> {
        ...
        controller?: ControllerFunction<T> | ControllerConstructor<T>;
        ...
    }

Actual:

    interface Component<T extends Controller> {
        ...
        controller: ControllerFunction<T> | ControllerConstructor<T>;
        ...
    }

Adding that question mark seems to do the trick.

andraaspar commented 8 years ago

Example:

This should be valid:

import * as m from 'mithril'

export default class Form implements Mithril.Component<any> {

    view() {
        return m('h3', 'Todos')
    }
}

But it emits an error:

Class 'Form' incorrectly implements interface 'Component<any>'.
  Property 'controller' is missing in type 'Form'.
dead-claudia commented 7 years ago

I'd merge a simple PR for this. (Good catch, BTW. It's easy to miss a single character like that.)