Skip to content

Add XMLHttpRequest types #432

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

Merged
merged 4 commits into from
Apr 13, 2018
Merged
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
47 changes: 25 additions & 22 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5088,12 +5088,12 @@ interface FormData {
getAll(name: string): FormDataEntryValue[];
has(name: string): boolean;
set(name: string, value: string | Blob, fileName?: string): void;
forEach(callbackfn: (value: FormDataEntryValue, key: string, parent: FormData) => void, thisArg?: any): void;
}

declare var FormData: {
prototype: FormData;
new(): FormData;
new(form: HTMLFormElement): FormData;
new(form?: HTMLFormElement): FormData;
};

interface GainNode extends AudioNode {
Expand Down Expand Up @@ -10423,12 +10423,11 @@ interface ProgressEvent extends Event {
readonly lengthComputable: boolean;
readonly loaded: number;
readonly total: number;
initProgressEvent(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, lengthComputableArg: boolean, loadedArg: number, totalArg: number): void;
}

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

interface PromiseRejectionEvent extends Event {
Expand Down Expand Up @@ -15700,8 +15699,7 @@ interface XMLHttpRequestEventMap extends XMLHttpRequestEventTargetEventMap {
"readystatechange": Event;
}

interface XMLHttpRequest extends EventTarget, XMLHttpRequestEventTarget {
msCaching: string;
interface XMLHttpRequest extends XMLHttpRequestEventTarget {
onreadystatechange: ((this: XMLHttpRequest, ev: Event) => any) | null;
readonly readyState: number;
readonly response: any;
Expand All @@ -15716,12 +15714,12 @@ interface XMLHttpRequest extends EventTarget, XMLHttpRequestEventTarget {
withCredentials: boolean;
abort(): void;
getAllResponseHeaders(): string;
getResponseHeader(header: string): string | null;
msCachingEnabled(): boolean;
open(method: string, url: string, async?: boolean, user?: string | null, password?: string | null): void;
getResponseHeader(name: string): string | null;
open(method: string, url: string): void;
open(method: string, url: string, async: boolean, username?: string | null, password?: string | null): void;
overrideMimeType(mime: string): void;
send(data?: any): void;
setRequestHeader(header: string, value: string): void;
send(body?: Document | BodyInit): void;
setRequestHeader(name: string, value: string): void;
readonly DONE: number;
readonly HEADERS_RECEIVED: number;
readonly LOADING: number;
Expand All @@ -15744,21 +15742,21 @@ declare var XMLHttpRequest: {
};

interface XMLHttpRequestEventTargetEventMap {
"abort": Event;
"error": ErrorEvent;
"load": Event;
"abort": ProgressEvent;
"error": ProgressEvent;
"load": ProgressEvent;
"loadend": ProgressEvent;
"loadstart": Event;
"loadstart": ProgressEvent;
"progress": ProgressEvent;
"timeout": ProgressEvent;
}

interface XMLHttpRequestEventTarget {
onabort: ((this: XMLHttpRequest, ev: Event) => any) | null;
onerror: ((this: XMLHttpRequest, ev: ErrorEvent) => any) | null;
onload: ((this: XMLHttpRequest, ev: Event) => any) | null;
interface XMLHttpRequestEventTarget extends EventTarget {
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: Event) => 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, options?: boolean | AddEventListenerOptions): void;
Expand All @@ -15767,7 +15765,12 @@ interface XMLHttpRequestEventTarget {
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
}

interface XMLHttpRequestUpload extends EventTarget, XMLHttpRequestEventTarget {
declare var XMLHttpRequestEventTarget: {
prototype: XMLHttpRequestEventTarget;
new(): XMLHttpRequestEventTarget;
};

interface XMLHttpRequestUpload extends XMLHttpRequestEventTarget {
addEventListener<K extends keyof XMLHttpRequestEventTargetEventMap>(type: K, listener: (this: XMLHttpRequestUpload, ev: XMLHttpRequestEventTargetEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof XMLHttpRequestEventTargetEventMap>(type: K, listener: (this: XMLHttpRequestUpload, ev: XMLHttpRequestEventTargetEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
Expand Down Expand Up @@ -16410,11 +16413,11 @@ type DOMHighResTimeStamp = number;
type PerformanceEntryList = PerformanceEntry[];
type BufferSource = ArrayBufferView | ArrayBuffer;
type DOMTimeStamp = number;
type FormDataEntryValue = File | string;
type ScrollBehavior = "auto" | "instant" | "smooth";
type ScrollLogicalPosition = "start" | "center" | "end" | "nearest";
type MouseWheelEvent = WheelEvent;
type ScrollRestoration = "auto" | "manual";
type FormDataEntryValue = string | File;
type InsertPosition = "beforebegin" | "afterbegin" | "beforeend" | "afterend";
type OrientationLockType = "any" | "natural" | "portrait" | "landscape" | "portrait-primary" | "portrait-secondary" | "landscape-primary"| "landscape-secondary";
type IDBValidKey = number | string | Date | BufferSource | IDBArrayKey;
Expand Down
47 changes: 25 additions & 22 deletions baselines/webworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -647,12 +647,12 @@ interface FormData {
getAll(name: string): FormDataEntryValue[];
has(name: string): boolean;
set(name: string, value: string | Blob, fileName?: string): void;
forEach(callbackfn: (value: FormDataEntryValue, key: string, parent: FormData) => void, thisArg?: any): void;
}

declare var FormData: {
prototype: FormData;
new(): FormData;
new(form: object): FormData;
new(form?: object): FormData;
};

interface GlobalFetch {
Expand Down Expand Up @@ -1172,12 +1172,11 @@ interface ProgressEvent extends Event {
readonly lengthComputable: boolean;
readonly loaded: number;
readonly total: number;
initProgressEvent(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, lengthComputableArg: boolean, loadedArg: number, totalArg: number): void;
}

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

interface PushEvent extends ExtendableEvent {
Expand Down Expand Up @@ -1619,8 +1618,7 @@ interface XMLHttpRequestEventMap extends XMLHttpRequestEventTargetEventMap {
"readystatechange": Event;
}

interface XMLHttpRequest extends EventTarget, XMLHttpRequestEventTarget {
msCaching: string;
interface XMLHttpRequest extends XMLHttpRequestEventTarget {
onreadystatechange: ((this: XMLHttpRequest, ev: Event) => any) | null;
readonly readyState: number;
readonly response: any;
Expand All @@ -1635,12 +1633,12 @@ interface XMLHttpRequest extends EventTarget, XMLHttpRequestEventTarget {
withCredentials: boolean;
abort(): void;
getAllResponseHeaders(): string;
getResponseHeader(header: string): string | null;
msCachingEnabled(): boolean;
open(method: string, url: string, async?: boolean, user?: string | null, password?: string | null): void;
getResponseHeader(name: string): string | null;
open(method: string, url: string): void;
open(method: string, url: string, async: boolean, username?: string | null, password?: string | null): void;
overrideMimeType(mime: string): void;
send(data?: any): void;
setRequestHeader(header: string, value: string): void;
send(body?: object | BodyInit): void;
setRequestHeader(name: string, value: string): void;
readonly DONE: number;
readonly HEADERS_RECEIVED: number;
readonly LOADING: number;
Expand All @@ -1663,21 +1661,21 @@ declare var XMLHttpRequest: {
};

interface XMLHttpRequestEventTargetEventMap {
"abort": Event;
"error": ErrorEvent;
"load": Event;
"abort": ProgressEvent;
"error": ProgressEvent;
"load": ProgressEvent;
"loadend": ProgressEvent;
"loadstart": Event;
"loadstart": ProgressEvent;
"progress": ProgressEvent;
"timeout": ProgressEvent;
}

interface XMLHttpRequestEventTarget {
onabort: ((this: XMLHttpRequest, ev: Event) => any) | null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the this type was intentional see microsoft/TypeScript#15101 and #275

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XMLHttpRequestUpload also extends XMLHttpRequestEventTarget, hmm. It doesn't have any properties so forcing XMLHttpRequest won't be an issue for now...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

onerror: ((this: XMLHttpRequest, ev: ErrorEvent) => any) | null;
onload: ((this: XMLHttpRequest, ev: Event) => any) | null;
interface XMLHttpRequestEventTarget extends EventTarget {
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: Event) => 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, options?: boolean | AddEventListenerOptions): void;
Expand All @@ -1686,7 +1684,12 @@ interface XMLHttpRequestEventTarget {
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
}

interface XMLHttpRequestUpload extends EventTarget, XMLHttpRequestEventTarget {
declare var XMLHttpRequestEventTarget: {
prototype: XMLHttpRequestEventTarget;
new(): XMLHttpRequestEventTarget;
};

interface XMLHttpRequestUpload extends XMLHttpRequestEventTarget {
addEventListener<K extends keyof XMLHttpRequestEventTargetEventMap>(type: K, listener: (this: XMLHttpRequestUpload, ev: XMLHttpRequestEventTargetEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof XMLHttpRequestEventTargetEventMap>(type: K, listener: (this: XMLHttpRequestUpload, ev: XMLHttpRequestEventTargetEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
Expand Down Expand Up @@ -1773,7 +1776,7 @@ type BodyInit = Blob | BufferSource | FormData | URLSearchParams | ReadableStrea
type RequestInfo = Request | string;
type PerformanceEntryList = PerformanceEntry[];
type BufferSource = ArrayBufferView | ArrayBuffer;
type FormDataEntryValue = string | File;
type FormDataEntryValue = File | string;
type IDBValidKey = number | string | Date | BufferSource | IDBArrayKey;
type AlgorithmIdentifier = string | Algorithm;
type AAGUID = string;
Expand Down
46 changes: 0 additions & 46 deletions inputfiles/addedTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -1622,48 +1622,6 @@
},
"no-interface-object": "1"
},
"FormData": {
"name": "FormData",
"methods": {
"method": {
"delete": {
"name": "delete",
"flavor": "Web",
"override-signatures": [
"delete(name: string): void"
]
},
"get": {
"name": "get",
"flavor": "Web",
"override-signatures": [
"get(name: string): FormDataEntryValue | null"
]
},
"getAll": {
"name": "getAll",
"flavor": "Web",
"override-signatures": [
"getAll(name: string): FormDataEntryValue[]"
]
},
"has": {
"name": "has",
"flavor": "Web",
"override-signatures": [
"has(name: string): boolean"
]
},
"set": {
"name": "set",
"flavor": "Web",
"override-signatures": [
"set(name: string, value: string | Blob, fileName?: string): void"
]
}
}
}
},
"ValidityState": {
"name": "ValidityState",
"properties": {
Expand Down Expand Up @@ -2954,10 +2912,6 @@
"override-type": "\"auto\" | \"manual\"",
"new-type": "ScrollRestoration"
},
{
"override-type": "string | File",
"new-type": "FormDataEntryValue"
},
{
"override-type": "\"beforebegin\" | \"afterbegin\" | \"beforeend\" | \"afterend\"",
"new-type": "InsertPosition"
Expand Down
89 changes: 89 additions & 0 deletions inputfiles/idl/XMLHttpRequest.widl
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
[Exposed=(Window,DedicatedWorker,SharedWorker)]
interface XMLHttpRequestEventTarget : EventTarget {
// event handlers
attribute EventHandler onloadstart;
attribute EventHandler onprogress;
attribute EventHandler onabort;
attribute EventHandler onerror;
attribute EventHandler onload;
attribute EventHandler ontimeout;
attribute EventHandler onloadend;
};

[Exposed=(Window,DedicatedWorker,SharedWorker)]
interface XMLHttpRequestUpload : XMLHttpRequestEventTarget {
};

enum XMLHttpRequestResponseType {
"",
"arraybuffer",
"blob",
"document",
"json",
"text"
};

[Constructor,
Exposed=(Window,DedicatedWorker,SharedWorker)]
interface XMLHttpRequest : XMLHttpRequestEventTarget {
// event handler
attribute EventHandler onreadystatechange;

// states
const unsigned short UNSENT = 0;
const unsigned short OPENED = 1;
const unsigned short HEADERS_RECEIVED = 2;
const unsigned short LOADING = 3;
const unsigned short DONE = 4;
readonly attribute unsigned short readyState;

// request
void open(ByteString method, USVString url);
void open(ByteString method, USVString url, boolean async, optional USVString? username = null, optional USVString? password = null);
void setRequestHeader(ByteString name, ByteString value);
attribute unsigned long timeout;
attribute boolean withCredentials;
[SameObject] readonly attribute XMLHttpRequestUpload upload;
void send(optional (Document or BodyInit)? body = null);
void abort();

// response
readonly attribute USVString responseURL;
readonly attribute unsigned short status;
readonly attribute ByteString statusText;
ByteString? getResponseHeader(ByteString name);
ByteString getAllResponseHeaders();
void overrideMimeType(DOMString mime);
attribute XMLHttpRequestResponseType responseType;
readonly attribute any response;
readonly attribute USVString responseText;
[Exposed=Window] readonly attribute Document? responseXML;
};
typedef (File or USVString) FormDataEntryValue;

[Constructor(optional HTMLFormElement form),
Exposed=(Window,Worker)]
interface FormData {
void append(USVString name, USVString value);
void append(USVString name, Blob blobValue, optional USVString filename);
void delete(USVString name);
FormDataEntryValue? get(USVString name);
sequence<FormDataEntryValue> getAll(USVString name);
boolean has(USVString name);
void set(USVString name, USVString value);
void set(USVString name, Blob blobValue, optional USVString filename);
iterable<USVString, FormDataEntryValue>;
};
[Constructor(DOMString type, optional ProgressEventInit eventInitDict),
Exposed=(Window,DedicatedWorker,SharedWorker)]
interface ProgressEvent : Event {
readonly attribute boolean lengthComputable;
readonly attribute unsigned long long loaded;
readonly attribute unsigned long long total;
};

dictionary ProgressEventInit : EventInit {
boolean lengthComputable = false;
unsigned long long loaded = 0;
unsigned long long total = 0;
};
4 changes: 4 additions & 0 deletions inputfiles/idlSources.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,9 @@
{
"url": "https://w3c.github.io/webrtc-pc/",
"title": "WebRTC"
},
{
"url": "https://xhr.spec.whatwg.org/",
"title": "XMLHttpRequest"
}
]
Loading