-
Notifications
You must be signed in to change notification settings - Fork 56
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
Drop DOM types #88
Drop DOM types #88
Conversation
This library may be used in non-DOM contexts, and the triple-slash directive pollutes the whole consumer, unfortunately. On top of that, fetch implementations vary slightly. For example, Node.js (Undici) response body is slightly different from DOM.
This would be great to have available. |
Thanks for providing the PR, and for letting me know about the Undici issue. However, making the typing of the library less strict and allowing the usage of When there are differences in the typing of the In order to use import fetchRetry from 'fetch-retry';
import { fetch as originalFetch } from 'undici'
const fetch = fetchRetry(originalFetch as any); When it comes to removing the triple-slash directive, I am concerned this would introduce a breaking change for older versions of node that does not have a native fetch implementation available. This is also an issue not specific to fetch-retry and rather the lack of a strict environment in TypeScript. I also think the issue is not severe enough to make As a workaround, have you tried using the --noResolve flag which instructs the TypeScript compiler to ignore triple-slash references? |
Thanks for dedicating time to this!
This PR makes the types more correct (and hence strict), not less.
This is debatable. DOM types can specify APIs which are wider than the standard.
But it doesn't,
I'd like to clarify that me and @Ludorio aren't using
This is a breaking change, but toward correctness. It's erroneous to have DOM types in universal or Node.js-only code.
There are several ways this can be worked around, but this PR attempts to solve the problem the "right" way. I haven't tried
I don't believe this breaks older Overall, I do encourage you to test this in various environments, to be safe 😉 I can't invest more time into this, I'm afraid, as we aren't using this library anymore. |
Thank you for your comment and detailed explanation @alecmev. After thinking about it more and better understanding the changes, I think it makes a lot of sense to make a new version with these changes applied. I think it's an elegant way of handling the fact that there are variations in the Exporting the types defined in the library is also a good practice and can be helpful for those who need it. The only change I will do is to rename the |
Thank you! |
This library may be used in non-DOM contexts, and the triple-slash directive pollutes the whole consumer, unfortunately. On top of that, fetch implementations vary slightly. For example, Node.js (Undici) response body is slightly different from DOM.
This is a breaking change for TypeScript users, because the
RequestInitWithRetry
is a generic type now, and requires atypeof global.fetch
or alike as its generic parameter.fetchBuilder
itself is unaffected, the type is inferred there.Also exported the rest of the types, because why not. Tested on a local maximum-strictness TypeScript project.