TypeScript Version: 2.0.3
Code
interface FormData {
append(name: any, value: any, blobName?: string): void;
}
Expected behavior:
FormData can actually do more than only append data. In general JS I can retrieve data set with append by calling getAll. This method is missing inside of the FormData interface which makes it impossible to use as the compiler won't finish without failures.
So I expect a set of returned data when calling FormData.getAll()
Actual behavior:
module/Application/assets/ts/d3-vanilla-fileupload.ts(274,12): error TS2339: Property 'getAll' does not exist on type 'FormData'.
V2A-16:area51 v2a$ tsc --out public/js/d3-fileupload.vanilla.js module/Application/assets/ts/d3-vanilla-fileupload.ts
module/Application/assets/ts/d3-vanilla-fileupload.ts(274,36): error TS2339: Property 'entries' does not exist on type 'FormData'.
V2A-16:area51 v2a$ tsc --out public/js/d3-fileupload.vanilla.js module/Application/assets/ts/d3-vanilla-fileupload.ts
As you can see the same goes for the method entries.
Is there a specific reason these methods were left out of the FormData interface?
This method isn't supported in all browsers. See https://developer.mozilla.org/en-US/docs/Web/API/FormData/getAll
@RyanCavanaugh Thanks for the quick respond. Any way I can go and work around this? The only way I can think of is going away from TS again. This obviously is something I wanna avoid though.
Just write
interface FormData {
getAll(): string[]
}
If that would be an option I'd already did it. But why would I wanna edit the original Interface?
You aren't editing the original interface. Interfaces are open ended by design. You are simply adding to it because you are asserting you are running in an environment where that method will be present.
Most helpful comment
You aren't editing the original interface. Interfaces are open ended by design. You are simply adding to it because you are asserting you are running in an environment where that method will be present.