I'm trying to port https://github.com/sindresorhus/got/blob/main/documentation/examples/advanced-creation.js#L43 to a typescript codebase, and yet I'm finding out that it is super hard to type Got internals (such as the next(), the promiseOrStream, the events, etc).
All of the "obvious" ones such as Request, Handler, GotReturn, etc., don't fit the bill for promiseOrStream, and no matter what type I set to it, typescript complains about the type of the handler function as it doesn't conform to the Handler type.
Furthermore, there is no guidance on typing "additional inputs" (in the above example, downloadLimit/uploadLimit) on the existing context type (so that instead of context.downloadLimit/context.uploadLimit
being unknown
due to context
being typed as Record<string, unknown>
, we could type the context as being Record<string, unknown>
for all other contexts and Record<string, number>
for downloadLimit/uploadLimit
- known options).
I feel like we need a general "improve typing experience for got.js internals" work/overhaul (given other issues with typing "internals" such as #2268), but at least for the scope of this issue, I'd like to know what the type of next()/promiseOrStream
is supposed to be, and how I could go about setting the type of that without upsetting typescript about the type of the handler function.
Thank you.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too