Skip to content

Commit

Permalink
react-native: Use number literals in TypeScript types for `FileReader…
Browse files Browse the repository at this point in the history
…` and `XMLHttpRequest` states (#36000)

Summary:
Mostly to improve compat in codebases where `lib.dom.d.ts` is loaded alongside RN. TS 5.0 updates to `lib.dom.d.ts` added number literals for these states as well so the abstract `number` type from RN was no longer compatible.

Forward-port of DefinitelyTyped/DefinitelyTyped#64144

Underlying flow types:
- https://github.com/facebook/react-native/blob/v0.71.1/Libraries/Blob/FileReader.js#L33-L35
- https://github.com/facebook/react-native/blob/v0.71.1/Libraries/Network/XMLHttpRequest.js#L54-L58

## Changelog

[GENERAL] [CHANGED] - Use number literals in TypeScript types for `FileReader` and `XMLHttpRequest` states

Pull Request resolved: #36000

Test Plan: - [x] DefinitelyTyped/DefinitelyTyped#64144 green

Reviewed By: christophpurrer

Differential Revision: D42849886

Pulled By: jacdebug

fbshipit-source-id: c3cf2ac4f5f53ab889a9190583486da4627d3dcc
  • Loading branch information
Sebastian Silbermann authored and facebook-github-bot committed Jan 30, 2023
1 parent 115dbe9 commit 8568b93
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions types/modules/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,11 @@ interface XMLHttpRequest extends EventTarget, XMLHttpRequestEventTarget {
overrideMimeType(mime: string): void;
send(data?: any): void;
setRequestHeader(header: string, value: string): void;
readonly DONE: number;
readonly HEADERS_RECEIVED: number;
readonly LOADING: number;
readonly OPENED: number;
readonly UNSENT: number;
readonly DONE: 4;
readonly HEADERS_RECEIVED: 2;
readonly LOADING: 3;
readonly OPENED: 1;
readonly UNSENT: 0;
addEventListener<K extends keyof XMLHttpRequestEventMap>(
type: K,
listener: (this: XMLHttpRequest, ev: XMLHttpRequestEventMap[K]) => any,
Expand All @@ -280,11 +280,11 @@ interface XMLHttpRequest extends EventTarget, XMLHttpRequestEventTarget {
declare var XMLHttpRequest: {
prototype: XMLHttpRequest;
new (): XMLHttpRequest;
readonly DONE: number;
readonly HEADERS_RECEIVED: number;
readonly LOADING: number;
readonly OPENED: number;
readonly UNSENT: number;
readonly DONE: 4;
readonly HEADERS_RECEIVED: 2;
readonly LOADING: 3;
readonly OPENED: 1;
readonly UNSENT: 0;
};

interface XMLHttpRequestEventTargetEventMap {
Expand Down Expand Up @@ -551,9 +551,9 @@ interface FileReader extends EventTarget {
// readAsBinaryString(blob: Blob): void;
readAsDataURL(blob: Blob): void;
readAsText(blob: Blob, encoding?: string): void;
readonly DONE: number;
readonly EMPTY: number;
readonly LOADING: number;
readonly DONE: 2;
readonly EMPTY: 0;
readonly LOADING: 1;
addEventListener<K extends keyof FileReaderEventMap>(
type: K,
listener: (this: FileReader, ev: FileReaderEventMap[K]) => any,
Expand All @@ -571,7 +571,7 @@ interface FileReader extends EventTarget {
declare var FileReader: {
prototype: FileReader;
new (): FileReader;
readonly DONE: number;
readonly EMPTY: number;
readonly LOADING: number;
readonly DONE: 2;
readonly EMPTY: 0;
readonly LOADING: 1;
};

0 comments on commit 8568b93

Please sign in to comment.