Skip to content

Commit

Permalink
feat: include type defintion
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickJS committed Jan 22, 2016
1 parent 71fab2a commit 007d326
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
},
"main": "lib/xhr2.js",
"browser": "lib/browser.js",
"typings": "xhr2.d.ts",
"directories": {
"doc": "doc",
"lib": "lib",
Expand Down
163 changes: 163 additions & 0 deletions xhr2.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
declare var Element: {
prototype: Element;
new(): Element;
}

interface Event {
bubbles: boolean;
cancelBubble: boolean;
cancelable: boolean;
currentTarget: EventTarget;
defaultPrevented: boolean;
eventPhase: number;
isTrusted: boolean;
returnValue: boolean;
srcElement: Element;
target: EventTarget;
timeStamp: number;
type: string;
initEvent(eventTypeArg: string, canBubbleArg: boolean, cancelableArg: boolean): void;
preventDefault(): void;
stopImmediatePropagation(): void;
stopPropagation(): void;
AT_TARGET: number;
BUBBLING_PHASE: number;
CAPTURING_PHASE: number;
}

declare var Event: {
prototype: Event;
new(type: string, eventInitDict?: EventInit): Event;
AT_TARGET: number;
BUBBLING_PHASE: number;
CAPTURING_PHASE: number;
}

interface EventInit {
bubbles?: boolean;
cancelable?: boolean;
}

interface EventListener {
(evt: Event): void;
}

interface EventListenerObject {
handleEvent(evt: Event): void;
}

interface ProgressEventInit extends EventInit {
lengthComputable?: boolean;
loaded?: number;
total?: number;
}

interface ErrorEvent extends Event {
colno: number;
error: any;
filename: string;
lineno: number;
message: string;
initErrorEvent(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, messageArg: string, filenameArg: string, linenoArg: number): void;
}

declare var ErrorEvent: {
prototype: ErrorEvent;
new(): ErrorEvent;
}


declare var ProgressEvent: {
prototype: ProgressEvent;
new(type: string, eventInitDict?: ProgressEventInit): ProgressEvent;
}

declare type EventListenerOrEventListenerObject = EventListener | EventListenerObject;

interface EventTarget {
addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
dispatchEvent(evt: Event): boolean;
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
}

interface XMLHttpRequestEventTarget {
onabort: (ev: Event) => any;
onerror: (ev: Event) => any;
onload: (ev: Event) => any;
onloadend: (ev: ProgressEvent) => any;
onloadstart: (ev: Event) => any;
onprogress: (ev: ProgressEvent) => any;
ontimeout: (ev: ProgressEvent) => any;
addEventListener(type: "abort", listener: (ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "error", listener: (ev: ErrorEvent) => any, useCapture?: boolean): void;
addEventListener(type: "load", listener: (ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "loadend", listener: (ev: ProgressEvent) => any, useCapture?: boolean): void;
addEventListener(type: "loadstart", listener: (ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "progress", listener: (ev: ProgressEvent) => any, useCapture?: boolean): void;
addEventListener(type: "timeout", listener: (ev: ProgressEvent) => any, useCapture?: boolean): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
}

interface XMLHttpRequest extends EventTarget, XMLHttpRequestEventTarget {
msCaching: string;
onreadystatechange: (ev: ProgressEvent) => any;
readyState: number;
response: any;
responseBody: any;
responseText: string;
responseType: string;
responseXML: any;
status: number;
statusText: string;
timeout: number;
upload: XMLHttpRequestUpload;
withCredentials: boolean;
abort(): void;
getAllResponseHeaders(): string;
getResponseHeader(header: string): string;
msCachingEnabled(): boolean;
open(method: string, url: string, async?: boolean, user?: string, password?: string): void;
overrideMimeType(mime: string): void;
send(data?: string): void;
send(data?: any): void;
setRequestHeader(header: string, value: string): void;
DONE: number;
HEADERS_RECEIVED: number;
LOADING: number;
OPENED: number;
UNSENT: number;
addEventListener(type: "abort", listener: (ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "error", listener: (ev: ErrorEvent) => any, useCapture?: boolean): void;
addEventListener(type: "load", listener: (ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "loadend", listener: (ev: ProgressEvent) => any, useCapture?: boolean): void;
addEventListener(type: "loadstart", listener: (ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "progress", listener: (ev: ProgressEvent) => any, useCapture?: boolean): void;
addEventListener(type: "readystatechange", listener: (ev: ProgressEvent) => any, useCapture?: boolean): void;
addEventListener(type: "timeout", listener: (ev: ProgressEvent) => any, useCapture?: boolean): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
}

declare var XMLHttpRequest: {
XMLHttpRequestUpload: XMLHttpRequestUpload;
XMLHttpRequest: XMLHttpRequest;
prototype: XMLHttpRequest;
new(): XMLHttpRequest;
DONE: number;
HEADERS_RECEIVED: number;
LOADING: number;
OPENED: number;
UNSENT: number;
create(): XMLHttpRequest;
nodejsSet(url: any): any;
}

interface XMLHttpRequestUpload extends EventTarget, XMLHttpRequestEventTarget {
addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
}

declare var XMLHttpRequestUpload: {
prototype: XMLHttpRequestUpload;
new(): XMLHttpRequestUpload;
}

export = XMLHttpRequest;

0 comments on commit 007d326

Please sign in to comment.