runeh / typical-fetch

Apache License 2.0
4 stars 0 forks source link

export FormData #23

Open braaar opened 1 year ago

braaar commented 1 year ago

I get a Type error when attempting to use FormData in a body (even though my project uses Node 18):

    .body(({ input: { username, password } }) => {
      const data = new FormData();

      data.append('username', username);
      data.append('password', password);
      data.append('grant_type', 'username');

      return data;
    })
Type 'FormData' is not assignable to type 'BodyType'.
        Property 'sort' is missing in type 'FormData' but required in type 'URLSearchParams'.

I can fix this by importing FormData from undici, but then I have to install undici in my project: import { FormData } from 'undici';

It would be nice to not have to install undici in my project. This could be achieved by exporting FormData in typical-fetch.

runeh commented 1 year ago

That sounds reasonable. I'll have a look this week.

braaar commented 1 year ago

Could it be this is actually a problem with @types/node and I'm just doing an XY problem here? Someone else should probably reproduce this behaviour to be sure. I'm not sure where the FormData type is coming from when I'm not actively importing it from anywhere.

simenandre commented 1 year ago

I had a interesting finding on this: In another project of mine, I'm using undici directly.

In that project, I had to use @types/node types (the global FormData type).