From 0d10046a3eb2d16123a5991990b62a7d7eea708f Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Thu, 15 May 2014 22:52:28 -0400 Subject: [PATCH] add typescript definition file --- archive/v0.1.13/mithril.min.zip | Bin 43732 -> 43732 bytes archive/v0.1.13/tools.html | 6 +++ docs/tools.md | 14 +++++++ mithril.d.ts | 64 ++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 mithril.d.ts diff --git a/archive/v0.1.13/mithril.min.zip b/archive/v0.1.13/mithril.min.zip index 36e585222e6b8ef4dab220262c9249d68c830fc7..1deb1c1fc10f12f8c06270d62ea84c43284b8fa7 100644 GIT binary patch delta 60 zcmca|mFdb=CY}IqW)?065NO)AktaiyscGBhGSz3+AUZB_w+E1(EWOGKM1`*ciB6uf G$^ig`o)-xK delta 60 zcmca|mFdb=CY}IqW)?065NPk*$djSU)ZV$dO!b*Hh>lC#?E$1GORus5QQ@mVqLZhr GasU8s+!h%C diff --git a/archive/v0.1.13/tools.html b/archive/v0.1.13/tools.html index 15060885..93640b6b 100644 --- a/archive/v0.1.13/tools.html +++ b/archive/v0.1.13/tools.html @@ -67,6 +67,12 @@

You can pre-compile Mithril templates to make them run faster. For more information see this page:

Compiling Templates


+

Typescript Support

+

There's a type definition file that you can use to add Mithril support to Typescript

+

mithril.d.ts

+

You can use it by adding a reference to your Typescript files. This will allow the compiler to type-check calls to the Mithril API.

+
/// <reference path="mithril.d.ts" />
+

Internet Explorer Compatibility

Mithril relies on some Ecmascript 5 features, namely: Array::indexOf and Object::keys, as well as the JSON object.

You can use polyfill libraries to support these features in IE7.

diff --git a/docs/tools.md b/docs/tools.md index 6f4bb9cd..ce2fe847 100644 --- a/docs/tools.md +++ b/docs/tools.md @@ -41,6 +41,20 @@ You can pre-compile Mithril templates to make them run faster. For more informat --- +### Typescript Support + +There's a type definition file that you can use to add Mithril support to Typescript + +[mithril.d.ts](mithril.d.ts) + +You can use it by adding a reference to your Typescript files. This will allow the compiler to type-check calls to the Mithril API. + +```javascript +/// +``` + +--- + ### Internet Explorer Compatibility Mithril relies on some Ecmascript 5 features, namely: `Array::indexOf` and `Object::keys`, as well as the `JSON` object. diff --git a/mithril.d.ts b/mithril.d.ts new file mode 100644 index 00000000..958c22c0 --- /dev/null +++ b/mithril.d.ts @@ -0,0 +1,64 @@ +//Mithril type definitions for Typescript + +interface MithrilStatic { + (selector: string, attributes: Object, children?: any): MithrilVirtualElement; + (selector: string, children?: any): MithrilVirtualElement; + prop(value?: any): (value?: any) => any; + withAttr(property: string, callback: (value: any) => void): (e: Event) => any; + module(rootElement: Element, module: MithrilModule): void; + trust(html: string): String + render(rootElement: Element, children?: any): void + render(rootElement: HTMLDocument, children?: any): void + redraw(): void + route(rootElement: Element, defaultRoute: string, routes: { [key: string]: MithrilModule }): void + route(rootElement: HTMLDocument, defaultRoute: string, routes: { [key: string]: MithrilModule }): void + route(path: string): void + route(): string; + route(element: Element, isInitialized: boolean): void; + request(options: MithrilXHROptions): MithrilPromise; + deferred(): MithrilDeferred; + sync(promises: MithrilPromise[]): MithrilPromise; + startComputation(): void; + endComputation(): void; +} + +interface MithrilVirtualElement { + tag: string; + attrs: Object; + children: any; +} + +interface MithrilModule { + controller: Function; + view: Function; +} + +interface MithrilDeferred { + resolve(value?: any): void; + reject(value?: any): void; + promise: MithrilPromise; +} + +interface MithrilPromise { + (value?: any): any; + then(successCallback?: (value: any) => any, errorCallback?: (value: any) => any): MithrilPromise; +} + +interface MithrilXHROptions { + method: string; + url: string; + user?: string; + password?: string; + data?: any; + background?: boolean; + unwrapSuccess?(data: any): any; + unwrapError?(data: any): any; + serialize?(dataToSerialize: any): string; + deserialize?(dataToDeserialize: string): any; + extract?(xhr: XMLHttpRequest, options: MithrilXHROptions); + type?(data: Object): void; + config?(xhr: XMLHttpRequest, options: MithrilXHROptions) +} + +declare var Mithril: MithrilStatic; +declare var m: MithrilStatic; \ No newline at end of file