Stricter TypeScript definitions
This commit is contained in:
parent
2369586167
commit
492eb2ed67
1 changed files with 140 additions and 54 deletions
194
mithril.d.ts
vendored
194
mithril.d.ts
vendored
|
|
@ -1,76 +1,162 @@
|
||||||
//Mithril type definitions for Typescript
|
//Mithril type definitions for Typescript
|
||||||
|
|
||||||
interface MithrilStatic {
|
interface MithrilStatic {
|
||||||
(selector: string, attributes: Object, children?: any): MithrilVirtualElement;
|
|
||||||
(selector: string, children?: any): MithrilVirtualElement;
|
(selector: string, attributes: MithrilAttributes, ...children: Array<string|MithrilVirtualElement>): MithrilVirtualElement;
|
||||||
prop(value?: any): (value?: any) => any;
|
(selector: string, ...children: Array<string|MithrilVirtualElement>): MithrilVirtualElement;
|
||||||
withAttr(property: string, callback: (value: any) => void): (e: Event) => any;
|
|
||||||
module(rootElement: Node, module?: MithrilModule): Object;
|
prop<T>(promise: MithrilPromise<T>) : MithrilPromiseProperty<T>;
|
||||||
trust(html: string): String;
|
prop<T>(value: T): MithrilProperty<T>;
|
||||||
render(rootElement: Element, children?: any): void;
|
prop(): MithrilProperty<Object>; // might be that this should be Property<any>
|
||||||
render(rootElement: HTMLDocument, children?: any): void;
|
|
||||||
redraw: {
|
withAttr(property: string, callback: (value: any) => void): (e: MithrilEvent) => any;
|
||||||
(): void;
|
|
||||||
strategy(key: string);
|
module<T extends MithrilController>(rootElement: Node, module: MithrilModule<T>): T;
|
||||||
};
|
module<T extends MithrilController>(rootElement: Node): T;
|
||||||
route: {
|
|
||||||
(rootElement:Element, defaultRoute:string, routes:{ [key: string]: MithrilModule }): void
|
trust(html: string): string;
|
||||||
(element: Element, isInitialized: boolean): void;
|
|
||||||
(rootElement:HTMLDocument, defaultRoute:string, routes:{ [key: string]: MithrilModule }): void;
|
render(rootElement: Element|HTMLDocument): void;
|
||||||
(path:string, params?:any, shouldReplaceHistory?:boolean): void;
|
render(rootElement: Element|HTMLDocument, children: MithrilVirtualElement, forceRecreation?: boolean): void;
|
||||||
(): string;
|
render(rootElement: Element|HTMLDocument, children: MithrilVirtualElement[], forceRecreation?: boolean): void;
|
||||||
param(key:string): string;
|
|
||||||
mode: string;
|
redraw: {
|
||||||
};
|
(force?: boolean): void;
|
||||||
request(options: MithrilXHROptions): MithrilPromise;
|
strategy: MithrilProperty<string>;
|
||||||
deferred(): MithrilDeferred;
|
}
|
||||||
sync(promises: MithrilPromise[]): MithrilPromise;
|
|
||||||
startComputation(): void;
|
route: {
|
||||||
endComputation(): void;
|
<T extends MithrilController>(rootElement: HTMLDocument, defaultRoute: string, routes: MithrilRoutes<T>): void;
|
||||||
deps(Object: any): Object;
|
<T extends MithrilController>(rootElement: Element, defaultRoute: string, routes: MithrilRoutes<T>): void;
|
||||||
|
|
||||||
|
(element: Element, isInitialized: boolean): void;
|
||||||
|
(path: string, params?: any, shouldReplaceHistory?: boolean): void;
|
||||||
|
(): string;
|
||||||
|
|
||||||
|
param(key: string): string;
|
||||||
|
mode: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
request<T>(options: MithrilXHROptions): MithrilPromise<T>;
|
||||||
|
|
||||||
|
deferred: {
|
||||||
|
onerror(e: Error): void;
|
||||||
|
<T>(): MithrilDeferred<T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
sync<T>(promises: MithrilPromise<T>[]): MithrilPromise<T[]>;
|
||||||
|
|
||||||
|
startComputation(): void;
|
||||||
|
endComputation(): void;
|
||||||
|
|
||||||
|
// For test suite
|
||||||
|
deps: {
|
||||||
|
(mockWindow: Window): Window;
|
||||||
|
factory: Object;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MithrilVirtualElement {
|
interface MithrilVirtualElement {
|
||||||
tag: string;
|
key?: number;
|
||||||
attrs: Object;
|
tag?: string;
|
||||||
children: any;
|
attrs?: MithrilAttributes;
|
||||||
|
children?: any[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MithrilModule {
|
// Configuration function for an element
|
||||||
controller: Function;
|
interface MithrilElementConfig {
|
||||||
view: Function;
|
(element: Element, isInitialized: boolean, context?: any): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MithrilDeferred {
|
// Attributes on a virtual element
|
||||||
resolve(value?: any): void;
|
interface MithrilAttributes {
|
||||||
reject(value?: any): void;
|
title?: string;
|
||||||
promise: MithrilPromise;
|
className?: string;
|
||||||
|
class?: string;
|
||||||
|
config?: MithrilElementConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MithrilPromise {
|
// Defines the subset of Event that Mithril needs
|
||||||
(value?: any): any;
|
interface MithrilEvent {
|
||||||
then(successCallback?: (value: any) => any, errorCallback?: (value: any) => any): MithrilPromise;
|
currentTarget: Element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface MithrilController {
|
||||||
|
(): any;
|
||||||
|
onunload?(evt: Event): any;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MithrilView<T extends MithrilController> {
|
||||||
|
(ctrl: T): string|MithrilVirtualElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MithrilModule<T extends MithrilController> {
|
||||||
|
controller: T;
|
||||||
|
view: MithrilView<T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MithrilProperty<T> {
|
||||||
|
(): T;
|
||||||
|
(value: T): T;
|
||||||
|
toJSON(): T;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MithrilPromiseProperty<T> extends MithrilPromise<T> {
|
||||||
|
(): T;
|
||||||
|
(value: T): T;
|
||||||
|
toJSON(): T;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MithrilRoutes<T extends MithrilController> {
|
||||||
|
[key: string]: MithrilModule<T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
interface MithrilDeferred<T> {
|
||||||
|
resolve(value?: T): void;
|
||||||
|
reject(value?: any): void;
|
||||||
|
promise: MithrilPromise<T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MithrilSuccessCallback<T, U> {
|
||||||
|
(value: T): U;
|
||||||
|
(value: T): MithrilPromise<U>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MithrilErrorCallback<U> {
|
||||||
|
(value: Error): U;
|
||||||
|
(value: string): U;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MithrilPromise<T> {
|
||||||
|
(): T;
|
||||||
|
(value: T): T;
|
||||||
|
then<U>(success: (value: T) => 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) => 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare var Mithril: MithrilStatic;
|
declare var Mithril: MithrilStatic;
|
||||||
declare var m: MithrilStatic;
|
declare var m: MithrilStatic;
|
||||||
|
|
||||||
declare module 'mithril' {
|
declare module 'mithril' {
|
||||||
export = MithrilStatic;
|
export = m;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue