I want to use FormData in typescript. Unfortunately, the generated typescript definition files do not support the FormData constructor with the form element, as described in Typescript Issue No. 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 incorrect:
error TS2346: The supplied parameters do not match any signature of the target call.
I want to use the following declaration:
declare var FormData: { prototype: FormData; new (form?: HTMLFormElement): FormData; }
But if I include this type definition, I get this error:
error TS2403: Subsequent variable declarations must be of the same type. The variable "FormData" must be of type "{new (): FormData; prototype: FormData;} ', but there is a type of' {new (form ?: HTMLFormElement): FormData; prototype: FormData;}".
How can I get around this problem?
source share