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

Add XMLHttpRequest types #432

Merged
merged 4 commits into from
Apr 13, 2018
Merged

Add XMLHttpRequest types #432

merged 4 commits into from
Apr 13, 2018

Conversation

saschanaz
Copy link
Contributor

@saschanaz saschanaz commented Apr 12, 2018

Add FormData.forEach, remove obsolete initProgressEvent, fix XMLHttpRequestEventTargetEventMap, etc.

Fixes microsoft/TypeScript#21414
Fixes microsoft/TypeScript#19830

@@ -641,18 +641,20 @@ declare var FileReaderSync: {
};

interface FormData {
append(name: string, value: string | Blob, fileName?: string): void;
append(name: string, value: string): void;
append(name: string, blobValue: Blob, filename?: string): void;
Copy link
Contributor

Choose a reason for hiding this comment

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

the previous overload was better.. since you can pass a value of type string | Blob

Copy link
Contributor Author

@saschanaz saschanaz Apr 12, 2018

Choose a reason for hiding this comment

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

I agree, but somehow the spec authors have decided to use two signatures. No idea why, maybe documentation purpose?

[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>;
};

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we can override these two methods to avoid breaking existing users.

Copy link
Contributor Author

@saschanaz saschanaz Apr 12, 2018

Choose a reason for hiding this comment

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

Ah, I just noted this is a breaking change, but anyway formData.append('str', 'str', 'str'); is invalid and throws on Firefox. I would say the spec signature is better to prevent unexpected runtime breakage.

f.append("abc", "abc", "abc")
// TypeError: Argument 2 of FormData.append is not an object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But the union problem... looks like there is no ideal solution here, I'll just override them to keep previous behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

i agree.. but append(string, sring|Blob) should just work fine.

delete(name: string): void;
get(name: string): FormDataEntryValue | null;
getAll(name: string): FormDataEntryValue[];
has(name: string): boolean;
set(name: string, value: string | Blob, fileName?: string): void;
Copy link
Contributor

Choose a reason for hiding this comment

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

same here.

"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

@@ -111,7 +111,7 @@ function emitDom() {
if (obj["callback-interfaces"]) result["callback-interfaces"]!.interface = filterInterface(obj["callback-interfaces"]!.interface, template["callback-interfaces"] && template["callback-interfaces"]!.interface);
if (obj.dictionaries) result.dictionaries!.dictionary = filterDictionary(obj.dictionaries.dictionary, template.dictionaries && template.dictionaries.dictionary);
if (obj.enums) result.enums!.enum = filterEnum(obj.enums.enum, template.enums && template.enums.enum);
if (obj.mixins) result.mixins!.mixin = filterInterface(obj.mixins.mixin, template.mixins && template.mixins.mixin);
if (obj.mixins) result.mixins!.mixin = filterProperties(obj.mixins.mixin, mixin => !(template.mixins && template.mixins!.mixin[mixin.name]));
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure i understand this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previous code removed mixin members, the changed one removes the mixin itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(XMLHttpRequestEventTarget was a mixin but now is an interface, so the previous one should be removed.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's really a copy of line 110.

if (obj["callback-functions"]) result["callback-functions"]!["callback-function"] = filterProperties(obj["callback-functions"]!["callback-function"], (cb) => !(template["callback-functions"] && template["callback-functions"]!["callback-function"][cb.name]));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants