diff --git a/mithril.d.ts b/mithril.d.ts index b966fe81..52ef8253 100644 --- a/mithril.d.ts +++ b/mithril.d.ts @@ -4,7 +4,31 @@ * This is the module containing all the types/declarations/etc. for Mithril */ declare namespace Mithril { + interface ChildArray extends Array {} + type Children = Child | ChildArray; + type Child = string | VirtualElement | Component; + interface Static { + /** + * Creates a virtual element for use with m.render, m.mount, etc. + * + * @param selector A simple CSS selector. May include SVG tags. Nested + * selectors are not supported. + * @param attributes Attributes to add. Any DOM attribute may be used + * as an attribute, although innerHTML and the like may be overwritten + * silently. + * @param children Child elements, components, and text to add. + * @return A virtual element. + * + * @see m.render + * @see m.mount + * @see m.component + */ + ( + selector: string, + ...children: Children[] + ): VirtualElement; + /** * Creates a virtual element for use with m.render, m.mount, etc. * @@ -23,7 +47,7 @@ declare namespace Mithril { ( selector: string, attributes: Attributes, - ...children: Array> + ...children: Children[] ): VirtualElement; /** @@ -42,40 +66,6 @@ declare namespace Mithril { ...args: any[] ): Component; - /** - * Creates a virtual element for use with m.render, m.mount, etc. - * - * @param selector A simple CSS selector. Nested selectors are not - * supported. - * @param children Child elements, components, and text to add. - * @return A virtual element. - * - * @see m.render - * @see m.mount - * @see m.component - */ - ( - selector: string, - ...children: Array> - ): VirtualElement; - - /** - * Initializes a component for use with m.render, m.mount, etc. - * Shorthand for m.component. - * - * @param selector A component. - * @param args Arguments to optionally pass to the component. - * @return A component. - * - * @see m.render - * @see m.mount - * @see m.component - */ - ( - component: Component, - ...args: any[] - ): Component; - /** * Creates a getter-setter function that wraps a Mithril promise. Useful * for uniform data access, m.withAttr, etc. @@ -119,22 +109,9 @@ declare namespace Mithril { */ withAttr( property: string, - callback: (value: any) => void, - callbackThis: any - ): (e: Event) => any; - - /** - * Returns a event handler that can be bound to an element, firing with - * the specified property. - * - * @param attributeName Name of the element's attribute to bind to. - * @param property The property to bind. - * @return A function suitable for listening to an event. - */ - withAttr( - attributeName: string, - property: BasicProperty - ) : (e: Event) => any; + callback: (value: any) => any, + callbackThis?: any + ): (e: Event) => void; /** * @deprecated Use m.mount instead @@ -308,7 +285,7 @@ declare namespace Mithril { * @param data The data to serialize. * @return The serialized string. */ - buildQueryString(data: Object): String + buildQueryString(data: Object): string; /** * Parse a query string into an object. @@ -316,7 +293,7 @@ declare namespace Mithril { * @param data The data to parse. * @return The parsed object data. */ - parseQueryString(data: String): Object + parseQueryString(data: string): Object; } /** @@ -427,25 +404,20 @@ declare namespace Mithril { * @see m */ interface VirtualElement { - /** - * A key to optionally associate with this element. - */ - key?: number; - /** * The tag name of this element. */ - tag?: string; + tag: string; /** * The attributes of this element. */ - attrs?: Attributes; + attrs: Attributes; /** * The children of this element. */ - children?: Array>; + children: Children[]; } /** @@ -531,8 +503,13 @@ declare namespace Mithril { config?: ElementConfig; /** - * Any other virtual element properties including attributes and - * event handlers + * A key to optionally associate with this element. + */ + key?: string | number; + + /** + * Any other virtual element properties, including attributes and event + * handlers. */ [property: string]: any; } @@ -556,7 +533,7 @@ declare namespace Mithril { * @see ControllerConstructor */ interface ControllerFunction { - (opts?: any): T; + (...args: any[]): T; } /** @@ -565,17 +542,7 @@ declare namespace Mithril { * @see ControllerFunction */ interface ControllerConstructor { - new (): T; - } - - /** - * This represents a view factory. - */ - interface View { - /** - * Creates a view out of virtual elements. - */ - (ctrl: T): VirtualElement; + new (...args: any[]): T; } /** @@ -597,7 +564,7 @@ declare namespace Mithril { * * @see m.component */ - view(ctrl?: T, opts?: any): VirtualElement; + view(ctrl?: T, ...args: any[]): VirtualElement; } /**