Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node-fetch - FormData not accepted as type for BodyInit #52601

Open
5 tasks done
tayloraucoin opened this issue Apr 26, 2021 · 3 comments
Open
5 tasks done

node-fetch - FormData not accepted as type for BodyInit #52601

tayloraucoin opened this issue Apr 26, 2021 · 3 comments

Comments

@tayloraucoin
Copy link

Is something wrong with CI or publishing infrastructure?

If you know how to fix the issue, make a pull request instead.

If you do not mention the authors the issue will be ignored.

Hey maintainers,

Seems like FormData should easily be accepted by BodyInit in @types/node-fetch. string works fine.

Missing something? Or a bug?

Not sure what the URLSearchParams is about. Looks like there is some related discussion on the topic: microsoft/TypeScript#30584

Screen Shot 2021-04-26 at 3 35 10 PM

Screen Shot 2021-04-26 at 3 35 54 PM

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node-fetch/index.d.ts

Thanks!

@nikcorg
Copy link
Contributor

nikcorg commented Apr 27, 2021

The FormData type that is part of the BodyInit union is imported from the form-data npm package. Perhaps this is an issue with the type definition of that package or the dependency needs to be upgraded. It seems to have gone up a whole major version since it was added as a dependency.

From what I can tell, the issue you're linking to is related to a browser environment, whereas node-fetch is a node library and I'm unsure how it is relevant.

Your screenshot doesn't reveal how you're constructing body, making it difficult to analyze the problem further. Are you sure this isn't a question that should be posted in the library's Github issues?

@eliellis
Copy link

eliellis commented Jun 16, 2021

Just had this problem. @tayloraucoin as per @nikcorg's comment, this can be resolved by simply adding import FormData from 'form-data' to your file's imports. The source of the error is from the fact the FormData type present in form-data and the FormData type present in Typescript's own browser type definitions don't have any overlap, giving you this type error.

@jimmywarting
Copy link

fyi, form-data is being discouraged in node-fetch@3
node-fetch/node-fetch#1212

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants