[@types/react-native] Added progress event to XHR as per spec (#34902)

* Added to progress event to XHR as per spec

* TEST: ProgressEvent
This commit is contained in:
avin-kavish
2019-04-29 00:12:33 -07:00
committed by Wesley Wigham
parent 2ed977bc7e
commit 671e555f44
2 changed files with 29 additions and 15 deletions
+21 -15
View File
@@ -139,6 +139,12 @@ type ResponseType_ = "basic" | "cors" | "default" | "error" | "opaque" | "opaque
// XMLHttpRequest
//
declare interface ProgressEvent extends Event {
readonly lengthComputable: boolean;
readonly loaded: number;
readonly total: number;
}
interface XMLHttpRequestEventMap extends XMLHttpRequestEventTargetEventMap {
readystatechange: Event;
}
@@ -193,23 +199,23 @@ declare var XMLHttpRequest: {
};
interface XMLHttpRequestEventTargetEventMap {
abort: Event;
error: Event;
load: Event;
loadend: Event;
loadstart: Event;
progress: Event;
timeout: Event;
abort: ProgressEvent;
error: ProgressEvent;
load: ProgressEvent;
loadend: ProgressEvent;
loadstart: ProgressEvent;
progress: ProgressEvent;
timeout: ProgressEvent;
}
interface XMLHttpRequestEventTarget {
onabort: ((this: XMLHttpRequest, ev: Event) => any) | null;
onerror: ((this: XMLHttpRequest, ev: Event) => any) | null;
onload: ((this: XMLHttpRequest, ev: Event) => any) | null;
onloadend: ((this: XMLHttpRequest, ev: Event) => any) | null;
onloadstart: ((this: XMLHttpRequest, ev: Event) => any) | null;
onprogress: ((this: XMLHttpRequest, ev: Event) => any) | null;
ontimeout: ((this: XMLHttpRequest, ev: Event) => any) | null;
onabort: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
onerror: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
onload: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
onloadend: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
onloadstart: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
onprogress: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
ontimeout: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
addEventListener<K extends keyof XMLHttpRequestEventTargetEventMap>(
type: K,
listener: (this: XMLHttpRequestEventTarget, ev: XMLHttpRequestEventTargetEventMap[K]) => any
@@ -240,4 +246,4 @@ declare var XMLHttpRequestUpload: {
new (): XMLHttpRequestUpload;
};
type XMLHttpRequestResponseType = "" | "arraybuffer" | "blob" | "document" | "json" | "text";
declare type XMLHttpRequestResponseType = "" | "arraybuffer" | "blob" | "document" | "json" | "text";
+8
View File
@@ -26,3 +26,11 @@ fetch(myRequest, myInit)
const init = { status: 200, statusText: "SuperSmashingGreat!" };
const myResponse = new Response(blob, init);
});
const xmlRequest = new XMLHttpRequest();
xmlRequest.addEventListener("load", (ev) => {
console.log(ev.lengthComputable)
console.log(ev.loaded)
console.log(ev.total)
});