From 671e555f444bb9be0ab14b1d05d73b7e6d9622de Mon Sep 17 00:00:00 2001 From: avin-kavish <48435155+avin-kavish@users.noreply.github.com> Date: Mon, 29 Apr 2019 12:42:33 +0530 Subject: [PATCH] [@types/react-native] Added progress event to XHR as per spec (#34902) * Added to progress event to XHR as per spec * TEST: ProgressEvent --- types/react-native/globals.d.ts | 36 +++++++++++++++++------------ types/react-native/test/globals.tsx | 8 +++++++ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/types/react-native/globals.d.ts b/types/react-native/globals.d.ts index fc9c2ea5e0..613fd663be 100644 --- a/types/react-native/globals.d.ts +++ b/types/react-native/globals.d.ts @@ -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( 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"; diff --git a/types/react-native/test/globals.tsx b/types/react-native/test/globals.tsx index cdbc5268a5..c2e3a2dcab 100644 --- a/types/react-native/test/globals.tsx +++ b/types/react-native/test/globals.tsx @@ -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) +});