Closed southpolesteve closed 5 years ago
Hey @southpolesteve , thanks for pointing that out. The purpose of this lib is to provide the same fetch api for browsers and node. If we added these extra fields, it would just shift the issue to the other side: instead of lacking fields for node, we would have unsupported field for browsers. That being said, I don't think it would be possible to tackle this issue at this moment.
I don't have advanced skills in TypeScript but maybe you could try to extend the Request class on your end.
There is RequestInit
interface in node-fetch
and same in cross-fetch
but they are different
Maybe something like that can be done
import { RequestInit as RequestInitNodeFetch } from 'node-fetch';
import { RequestInit as RequestInitCrossFetch } from 'cross-fetch';
interface RequestInit = RequestInitNodeFetch | RequestInitCrossFetch;
fetch(URL, {...params} as RequestInit);
just a suggestion, haven't tested
node-fetch adds some extra fields to the fetch options interface: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node-fetch/index.d.ts#L24-L33
Would you be open to adding these here as well? The lack of the
agent
field is specifically causing me trouble at the moment. Our package consumers use custom agents on the server. They don't apply to browser users.Ideally the extra fields could be conditional based on the environment, but I am not sure of a way to do that with TypeScript.