Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: include type defintion #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;