add typescript definition file

This commit is contained in:
Leo Horie 2014-05-15 22:52:28 -04:00
parent 917f1e1d6b
commit 0d10046a3e
4 changed files with 84 additions and 0 deletions

Binary file not shown.

View file

@ -67,6 +67,12 @@
<p>You can pre-compile Mithril templates to make them run faster. For more information see this page:</p> <p>You can pre-compile Mithril templates to make them run faster. For more information see this page:</p>
<p><a href="compiling-templates.html">Compiling Templates</a></p> <p><a href="compiling-templates.html">Compiling Templates</a></p>
<hr> <hr>
<h3 id="typescript-support">Typescript Support</h3>
<p>There&#39;s a type definition file that you can use to add Mithril support to Typescript</p>
<p><a href="mithril.d.ts">mithril.d.ts</a></p>
<p>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.</p>
<pre><code class="lang-javascript">/// &lt;reference path=&quot;mithril.d.ts&quot; /&gt;</code></pre>
<hr>
<h3 id="internet-explorer-compatibility">Internet Explorer Compatibility</h3> <h3 id="internet-explorer-compatibility">Internet Explorer Compatibility</h3>
<p>Mithril relies on some Ecmascript 5 features, namely: <code>Array::indexOf</code> and <code>Object::keys</code>, as well as the <code>JSON</code> object.</p> <p>Mithril relies on some Ecmascript 5 features, namely: <code>Array::indexOf</code> and <code>Object::keys</code>, as well as the <code>JSON</code> object.</p>
<p>You can use polyfill libraries to support these features in IE7.</p> <p>You can use polyfill libraries to support these features in IE7.</p>

View file

@ -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
/// <reference path="mithril.d.ts" />
```
---
### Internet Explorer Compatibility ### Internet Explorer Compatibility
Mithril relies on some Ecmascript 5 features, namely: `Array::indexOf` and `Object::keys`, as well as the `JSON` object. Mithril relies on some Ecmascript 5 features, namely: `Array::indexOf` and `Object::keys`, as well as the `JSON` object.

64
mithril.d.ts vendored Normal file
View file

@ -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;