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?