Merge pull request #460 from cbowdon/typescript_stricter_defs

Typescript stricter defs
This commit is contained in:
Leo Horie 2015-02-18 20:17:26 -05:00
commit a795c1ba1d

179
mithril.d.ts vendored
View file

@ -2,161 +2,164 @@
interface MithrilStatic { interface MithrilStatic {
(selector: string, attributes: MithrilAttributes, ...children: Array<string|MithrilVirtualElement>): MithrilVirtualElement; (selector: string, attributes: MithrilAttributes, ...children: Array<string|MithrilVirtualElement>): MithrilVirtualElement;
(selector: string, ...children: Array<string|MithrilVirtualElement>): MithrilVirtualElement; (selector: string, ...children: Array<string|MithrilVirtualElement>): MithrilVirtualElement;
prop<T>(promise: MithrilPromise<T>) : MithrilPromiseProperty<T>; prop<T>(promise: MithrilPromise<T>) : MithrilPromiseProperty<T>;
prop<T>(value: T): MithrilProperty<T>; prop<T>(value: T): MithrilProperty<T>;
prop(): MithrilProperty<Object>; // might be that this should be Property<any> prop(): MithrilProperty<Object>; // might be that this should be Property<any>
withAttr(property: string, callback: (value: any) => void): (e: MithrilEvent) => any; withAttr(property: string, callback: (value: any) => void): (e: MithrilEvent) => any;
module<T extends MithrilController>(rootElement: Node, module: MithrilModule<T>): T; module<T extends MithrilController>(rootElement: Node, module: MithrilModule<T>): T;
module<T extends MithrilController>(rootElement: Node): T; module<T extends MithrilController>(rootElement: Node): T;
trust(html: string): string; trust(html: string): string;
render(rootElement: Element|HTMLDocument): void; render(rootElement: Element|HTMLDocument): void;
render(rootElement: Element|HTMLDocument, children: MithrilVirtualElement, forceRecreation?: boolean): void; render(rootElement: Element|HTMLDocument, children: MithrilVirtualElement, forceRecreation?: boolean): void;
render(rootElement: Element|HTMLDocument, children: MithrilVirtualElement[], forceRecreation?: boolean): void; render(rootElement: Element|HTMLDocument, children: MithrilVirtualElement[], forceRecreation?: boolean): void;
redraw: { redraw: {
(force?: boolean): void; (force?: boolean): void;
strategy: MithrilProperty<string>; strategy: MithrilProperty<string>;
} }
route: { route: {
<T extends MithrilController>(rootElement: HTMLDocument, defaultRoute: string, routes: MithrilRoutes<T>): void; <T extends MithrilController>(rootElement: HTMLDocument, defaultRoute: string, routes: MithrilRoutes<T>): void;
<T extends MithrilController>(rootElement: Element, defaultRoute: string, routes: MithrilRoutes<T>): void; <T extends MithrilController>(rootElement: Element, defaultRoute: string, routes: MithrilRoutes<T>): void;
(element: Element, isInitialized: boolean): void; (element: Element, isInitialized: boolean): void;
(path: string, params?: any, shouldReplaceHistory?: boolean): void; (path: string, params?: any, shouldReplaceHistory?: boolean): void;
(): string; (): string;
param(key: string): string; param(key: string): string;
mode: string; mode: string;
} }
request<T>(options: MithrilXHROptions): MithrilPromise<T>; request<T>(options: MithrilXHROptions): MithrilPromise<T>;
deferred: { deferred: {
onerror(e: Error): void; onerror(e: Error): void;
<T>(): MithrilDeferred<T>; <T>(): MithrilDeferred<T>;
} }
sync<T>(promises: MithrilPromise<T>[]): MithrilPromise<T[]>; sync<T>(promises: MithrilPromise<T>[]): MithrilPromise<T[]>;
startComputation(): void; startComputation(): void;
endComputation(): void; endComputation(): void;
// For test suite // For test suite
deps: { deps: {
(mockWindow: Window): Window; (mockWindow: Window): Window;
factory: Object; factory: Object;
} }
} }
interface MithrilVirtualElement { interface MithrilVirtualElement {
key?: number; key?: number;
tag?: string; tag?: string;
attrs?: MithrilAttributes; attrs?: MithrilAttributes;
children?: any[]; children?: any[];
} }
// Configuration function for an element // Configuration function for an element
interface MithrilElementConfig { interface MithrilElementConfig {
(element: Element, isInitialized: boolean, context?: any): void; (element: Element, isInitialized: boolean, context?: any): void;
} }
// Attributes on a virtual element // Attributes on a virtual element
interface MithrilAttributes { interface MithrilAttributes {
title?: string; title?: string;
className?: string; className?: string;
class?: string; class?: string;
config?: MithrilElementConfig; config?: MithrilElementConfig;
} }
// Defines the subset of Event that Mithril needs // Defines the subset of Event that Mithril needs
interface MithrilEvent { interface MithrilEvent {
currentTarget: Element; currentTarget: Element;
} }
interface MithrilController { interface MithrilController {
(): any; onunload?(evt: Event): any;
onunload?(evt: Event): any; }
interface MithrilControllerFunction extends MithrilController {
(): any;
} }
interface MithrilView<T extends MithrilController> { interface MithrilView<T extends MithrilController> {
(ctrl: T): string|MithrilVirtualElement; (ctrl: T): string|MithrilVirtualElement;
} }
interface MithrilModule<T extends MithrilController> { interface MithrilModule<T extends MithrilController> {
controller: T; controller: MithrilControllerFunction|{ new(): T };
view: MithrilView<T>; view: MithrilView<T>;
} }
interface MithrilProperty<T> { interface MithrilProperty<T> {
(): T; (): T;
(value: T): T; (value: T): T;
toJSON(): T; toJSON(): T;
} }
interface MithrilPromiseProperty<T> extends MithrilPromise<T> { interface MithrilPromiseProperty<T> extends MithrilPromise<T> {
(): T; (): T;
(value: T): T; (value: T): T;
toJSON(): T; toJSON(): T;
} }
interface MithrilRoutes<T extends MithrilController> { interface MithrilRoutes<T extends MithrilController> {
[key: string]: MithrilModule<T>; [key: string]: MithrilModule<T>;
} }
interface MithrilDeferred<T> { interface MithrilDeferred<T> {
resolve(value?: T): void; resolve(value?: T): void;
reject(value?: any): void; reject(value?: any): void;
promise: MithrilPromise<T>; promise: MithrilPromise<T>;
} }
interface MithrilSuccessCallback<T, U> { interface MithrilSuccessCallback<T, U> {
(value: T): U; (value: T): U;
(value: T): MithrilPromise<U>; (value: T): MithrilPromise<U>;
} }
interface MithrilErrorCallback<U> { interface MithrilErrorCallback<U> {
(value: Error): U; (value: Error): U;
(value: string): U; (value: string): U;
} }
interface MithrilPromise<T> { interface MithrilPromise<T> {
(): T; (): T;
(value: T): T; (value: T): T;
then<U>(success: (value: T) => U): MithrilPromise<U>; then<U>(success: (value: T) => U): MithrilPromise<U>;
then<U>(success: (value: T) => MithrilPromise<U>): MithrilPromise<U>; then<U>(success: (value: T) => MithrilPromise<U>): MithrilPromise<U>;
then<U,V>(success: (value: T) => U, error: (value: Error) => V): MithrilPromise<U>|MithrilPromise<V>; then<U,V>(success: (value: T) => U, error: (value: Error) => V): MithrilPromise<U>|MithrilPromise<V>;
then<U,V>(success: (value: T) => MithrilPromise<U>, error: (value: Error) => V): MithrilPromise<U>|MithrilPromise<V>; then<U,V>(success: (value: T) => MithrilPromise<U>, error: (value: Error) => V): MithrilPromise<U>|MithrilPromise<V>;
} }
interface MithrilXHROptions { interface MithrilXHROptions {
method?: string; method?: string;
url: string; url: string;
user?: string; user?: string;
password?: string; password?: string;
data?: any; data?: any;
background?: boolean; background?: boolean;
unwrapSuccess?(data: any): any; unwrapSuccess?(data: any): any;
unwrapError?(data: any): any; unwrapError?(data: any): any;
serialize?(dataToSerialize: any): string; serialize?(dataToSerialize: any): string;
deserialize?(dataToDeserialize: string): any; deserialize?(dataToDeserialize: string): any;
extract?(xhr: XMLHttpRequest, options: MithrilXHROptions): string; extract?(xhr: XMLHttpRequest, options: MithrilXHROptions): string;
type?(data: Object): void; type?(data: Object): void;
config?(xhr: XMLHttpRequest, options: MithrilXHROptions): XMLHttpRequest; config?(xhr: XMLHttpRequest, options: MithrilXHROptions): XMLHttpRequest;
dataType?: string; dataType?: string;
} }
declare var Mithril: MithrilStatic; declare var Mithril: MithrilStatic;
declare var m: MithrilStatic; declare var m: MithrilStatic;
declare module 'mithril' { declare module 'mithril' {
export = m; export = m;
} }