mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 21:10:23 +00:00
Type signature fixes
This commit is contained in:
Vendored
+34
-34
@@ -1,13 +1,11 @@
|
||||
// Type definitions for Mithril 1.1
|
||||
// Project: http://lhorie.github.io/mithril/
|
||||
// Definitions by: Leo Horie <https://github.com/lhorie>, Chris Bowdon <https://github.com/cbowdon>, Mike Linkovich <https://github.com/spacejack>, András Parditka <https://github.com/andraaspar>
|
||||
// Project: https://mithril.js.org/
|
||||
// Definitions by: Mike Linkovich <https://github.com/spacejack>, András Parditka <https://github.com/andraaspar>, Isiah Meadows <https://github.com/isiahmeadows>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
declare namespace Mithril {
|
||||
export interface Lifecycle<Attrs, State> {
|
||||
/** Any property attached to the component object is copied for every instance of the component. This allows simple state initialization. */
|
||||
[propName: string]: any;
|
||||
/** The oninit hook is called before a vnode is touched by the virtual DOM engine. */
|
||||
oninit?(this: State, vnode: Vnode<Attrs, State>): any;
|
||||
/** The oncreate hook is called after a DOM element is created and attached to the document. */
|
||||
@@ -83,14 +81,12 @@ declare namespace Mithril {
|
||||
(element: Element, component: null): void;
|
||||
}
|
||||
|
||||
/** Creates an event handler which takes the value of the specified DOM element property and calls a function with it as the argument. */
|
||||
export type WithAttr = (name: string, callback: (value: any) => any, thisArg?: any) => (e: { currentTarget: any, [p: string]: any }) => void;
|
||||
|
||||
/** Returns an object with key/value pairs parsed from a string of the form: ?a=1&b=2 */
|
||||
export type ParseQueryString = (queryString: string) => { [p: string]: any };
|
||||
|
||||
/** Turns the key/value pairs of an object into a string of the form: a=1&b=2 */
|
||||
export type BuildQueryString = (values: { [p: string]: any }) => string;
|
||||
export interface WithAttr {
|
||||
/** Creates an event handler which takes the value of the specified DOM element property and calls a function with it as the argument. */
|
||||
(name: string, callback: (value: any) => any): (e: { currentTarget: any, [p: string]: any }) => void;
|
||||
/** Creates an event handler which takes the value of the specified DOM element property and calls a function with it as the argument. */
|
||||
<T>(name: string, callback: (this: T, value: any) => any, thisArg: T): (e: { currentTarget: any, [p: string]: any }) => void;
|
||||
}
|
||||
|
||||
export interface RequestOptions<T> {
|
||||
/** The HTTP method to use. */
|
||||
@@ -108,7 +104,7 @@ declare namespace Mithril {
|
||||
/** Exposes the underlying XMLHttpRequest object for low-level configuration. */
|
||||
config?(xhr: XMLHttpRequest): any;
|
||||
/** Headers to append to the request before sending it. */
|
||||
headers?: any;
|
||||
headers?: { [key: string]: string };
|
||||
/** A constructor to be applied to each object in the response. */
|
||||
type?: new (o: any) => any;
|
||||
/** A serialization method to be applied to data. Defaults to JSON.stringify, or if options.data is an instance of FormData, defaults to the identity function. */
|
||||
@@ -116,21 +112,16 @@ declare namespace Mithril {
|
||||
/** A deserialization method to be applied to the response. Defaults to a small wrapper around JSON.parse that returns null for empty responses. */
|
||||
deserialize?(data: string): T;
|
||||
/** A hook to specify how the XMLHttpRequest response should be read. Useful for reading response headers and cookies. Defaults to a function that returns xhr.responseText */
|
||||
extract?(xhr: XMLHttpRequest, options: RequestOptions<T>): T;
|
||||
extract?(xhr: XMLHttpRequest, options: this): T;
|
||||
/** Force the use of the HTTP body section for data in GET requests when set to true, or the use of querystring for other HTTP methods when set to false. Defaults to false for GET requests and true for other methods. */
|
||||
useBody?: boolean;
|
||||
/** If false, redraws mounted components upon completion of the request. If true, it does not. */
|
||||
background?: boolean;
|
||||
}
|
||||
|
||||
export interface RequestOptionsAll<T> extends RequestOptions<T> {
|
||||
/** The URL to send the request to. */
|
||||
url: string;
|
||||
}
|
||||
|
||||
export interface Request {
|
||||
/** Makes an XHR request and returns a promise. */
|
||||
<T>(options: RequestOptionsAll<T>): Promise<T>;
|
||||
<T>(options: RequestOptions<T> & { url: string }): Promise<T>;
|
||||
/** Makes an XHR request and returns a promise. */
|
||||
<T>(url: string, options?: RequestOptions<T>): Promise<T>;
|
||||
}
|
||||
@@ -148,14 +139,9 @@ declare namespace Mithril {
|
||||
background?: boolean;
|
||||
}
|
||||
|
||||
export interface JsonpOptionsAll extends JsonpOptions {
|
||||
/** The URL to send the request to. */
|
||||
url: string;
|
||||
}
|
||||
|
||||
export interface Jsonp {
|
||||
/** Makes a JSON-P request and returns a promise. */
|
||||
<T>(options: JsonpOptionsAll): Promise<T>;
|
||||
<T>(options: JsonpOptions & { url: string }): Promise<T>;
|
||||
/** Makes a JSON-P request and returns a promise. */
|
||||
<T>(url: string, options?: JsonpOptions): Promise<T>;
|
||||
}
|
||||
@@ -190,10 +176,10 @@ declare namespace Mithril {
|
||||
redraw: Redraw;
|
||||
request: Request;
|
||||
jsonp: Jsonp;
|
||||
/** Parse a query string into an object. */
|
||||
parseQueryString: ParseQueryString;
|
||||
/** Serialize an object into a query string. */
|
||||
buildQueryString: BuildQueryString;
|
||||
/** Returns an object with key/value pairs parsed from a string of the form: ?a=1&b=2 */
|
||||
parseQueryString(queryString: string): { [p: string]: any };
|
||||
/** Turns the key/value pairs of an object into a string of the form: a=1&b=2 */
|
||||
buildQueryString(values: { [p: string]: any }): string;
|
||||
/** A string containing the semver value for the current Mithril release. */
|
||||
version: string;
|
||||
}
|
||||
@@ -222,7 +208,7 @@ declare namespace Mithril {
|
||||
|
||||
// In some lifecycle methods, Vnode will have a dom property
|
||||
// and possibly a domSize property.
|
||||
export interface VnodeDOM<Attrs, State> extends Vnode<Attrs, State> {
|
||||
export interface VnodeDOM<Attrs, State extends Lifecycle<Attrs, State>> extends Vnode<Attrs, State> {
|
||||
/** Points to the element that corresponds to the vnode. */
|
||||
dom: Element;
|
||||
/** This defines the number of DOM elements that the vnode represents (starting from the element referenced by the dom property). */
|
||||
@@ -233,17 +219,31 @@ declare namespace Mithril {
|
||||
|
||||
export interface CVnodeDOM<A> extends VnodeDOM<A, ClassComponent<A>> { }
|
||||
|
||||
/** Components are a mechanism to encapsulate parts of a view to make code easier to organize and/or reuse. Any Javascript object that has a view method is a Mithril component. Components can be consumed via the m() utility. */
|
||||
/** Components are a mechanism to encapsulate parts of a view to make code easier to organize and/or reuse. Any Javascript object that has a view method can be used as a Mithril component. Components can be consumed via the m() utility. */
|
||||
export interface Component<Attrs, State extends Lifecycle<Attrs, State>> extends Lifecycle<Attrs, State> {
|
||||
/** Creates a view out of virtual elements. */
|
||||
view(this: State, vnode: Vnode<Attrs, State>): Children | null | void;
|
||||
}
|
||||
|
||||
/** Components are a mechanism to encapsulate parts of a view to make code easier to organize and/or reuse. Any class that implements a view method can be used as a Mithril component. Components can be consumed via the m() utility. */
|
||||
export interface ClassComponent<A> extends Lifecycle<A, ClassComponent<A>> {
|
||||
view(this: ClassComponent<A>, vnode: CVnode<A>): Children | null | void;
|
||||
/** The oninit hook is called before a vnode is touched by the virtual DOM engine. */
|
||||
oninit?(vnode: Vnode<A, this>): any;
|
||||
/** The oncreate hook is called after a DOM element is created and attached to the document. */
|
||||
oncreate?(vnode: VnodeDOM<A, this>): any;
|
||||
/** The onbeforeupdate hook is called before a vnode is diffed in a update. */
|
||||
onbeforeremove?(vnode: VnodeDOM<A, this>): Promise<any> | void;
|
||||
/** The onupdate hook is called after a DOM element is updated, while attached to the document. */
|
||||
onremove?(vnode: VnodeDOM<A, this>): any;
|
||||
/** The onbeforeremove hook is called before a DOM element is detached from the document. If a Promise is returned, Mithril only detaches the DOM element after the promise completes. */
|
||||
onbeforeupdate?(vnode: Vnode<A, this>, old: VnodeDOM<A, this>): boolean | void;
|
||||
/** The onremove hook is called before a DOM element is removed from the document. */
|
||||
onupdate?(vnode: VnodeDOM<A, this>): any;
|
||||
/** Creates a view out of virtual elements. */
|
||||
view(vnode: CVnode<A>): Children | null | void;
|
||||
}
|
||||
|
||||
// Factory component
|
||||
/** Components are a mechanism to encapsulate parts of a view to make code easier to organize and/or reuse. Any function that returns an object with a view method can be used as a Mithril component. Components can be consumed via the m() utility. */
|
||||
export type FactoryComponent<A> = (vnode: Vnode<A, {}>) => Component<A, {}>
|
||||
|
||||
/** Components are a mechanism to encapsulate parts of a view to make code easier to organize and/or reuse. Any Javascript object that has a view method is a Mithril component. Components can be consumed via the m() utility. */
|
||||
|
||||
Vendored
+1
-3
@@ -1,6 +1,4 @@
|
||||
declare namespace Stream {
|
||||
export type Combiner<T> = (...streams: any[]) => T;
|
||||
|
||||
export interface Stream<T> {
|
||||
/** Returns the value of the stream. */
|
||||
(): T;
|
||||
@@ -26,7 +24,7 @@ declare namespace Stream {
|
||||
/** Creates a stream. */
|
||||
<T>(value?: T): Stream<T>;
|
||||
/** Creates a computed stream that reactively updates if any of its upstreams are updated. */
|
||||
combine<T>(combiner: Combiner<T>, streams: Stream<any>[]): Stream<T>;
|
||||
combine<T>(combiner: (...streams: any[]) => T, streams: Stream<any>[]): Stream<T>;
|
||||
/** Creates a stream whose value is the array of values from an array of streams. */
|
||||
merge(streams: Stream<any>[]): Stream<any[]>;
|
||||
/** Creates a new stream with the results of calling the function on every incoming stream with and accumulator and the incoming value. */
|
||||
|
||||
Reference in New Issue
Block a user