TypeScript Version: 3.4.0-dev.20190323
Search Terms:
URLSearchParams, FormData
Code
let form = document.createElement('form')
console.log(new URLSearchParams(new FormData(form)))
Expected behavior:
compilation succeeds and an (empty) URLSearchParams instance is constructed using the provided FormData. The above code runs without issue on Chrome 73 and Firefox 67 for me.
Actual behavior:
compilation fails because URLSearchParams doesn't explicitly allow an argument of type FormData as input to the constructor.
Argument of type 'FormData' is not assignable to parameter of type 'string | Record<string, string> | URLSearchParams | string[][]'.
Property 'sort' is missing in type 'FormData' but required in type 'URLSearchParams'.
Playground Link:
link
Related Issues:
If all that's required for this is to add | FormData to the constructor signature, I'm happy to PR.
@thatbudakguy - in the meantime, do you have a workaround for this?
@leonstafford my current workaround is just // @ts-ignore, sadly.
Another workaround is: new URLSearchParams(new FormData(event.currentTarget) as any)
Is there a deadline for this bug to be fixed?
No? Yes? When?
any news?
Most helpful comment
Another workaround is:
new URLSearchParams(new FormData(event.currentTarget) as any)