I want to use FormData in typescript. Unfortunately, the generated typescript definition files doesn't support a FormData constructor with a Form Element as detailed in Typescript Issue #1074.
I have the following code:
var formEl = <HTMLFormElement> document.getElementById("myForm");
var formData = new FormData(formEl);
The code gives the following error because the generated definition is wrong:
error TS2346: Supplied parameters do not match any signature of call target.
I want to use the following declaration:
declare var FormData: {
prototype: FormData;
new (form?: HTMLFormElement): FormData;
}
But, if I include that type definition, I get this error:
error TS2403: Subsequent variable declarations must have the same type. Variable 'FormData' must be of type '{ new (): FormData; prototype: FormData; }', but here has type '{ new (form?: HTMLFormElement): FormData; prototype: FormData; }'.
How can I work around this issue?
How can I work around this issue?
Send a PR.
Update the shipped lib.d.ts
in place:
declare var FormData: {
prototype: FormData;
new (form?: HTMLFormElement): FormData;
}
Copy and customize lib.d.ts
and compile with --noLib
and manually reference your custom lib.d.ts
.
Bypass the type-checker
var formEl = <HTMLFormElement> document.getElementById("myForm");
var formData = new window['FormData'](formEl);
There is a bug in the VS2017 typescript libraries (which may have been fixed in the April 2017 update). You can around the error you noted by turning off the LanguageService in Tools|Options|Text Editor|JavaScript/TypeScript|LanguageService Just uncheck the "Enable the new JavaScript language service." checkbox.
More details of the issue are on https://developercommunity.visualstudio.com/content/problem/25310/unload-projects-hangs-on-close-solution.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With