unsplash-js icon indicating copy to clipboard operation
unsplash-js copied to clipboard

Unable to set the fetch agent

Open PhilHannent opened this issue 3 years ago • 1 comments

Steps to Reproduce

To make use of socket reuse via HTTP keep alive's , we have been setting the agent on our fetch requests and using the library to help:

https://www.npmjs.com/package/agentkeepalive

As per this documentation recommendation: https://docs.microsoft.com/en-us/azure/app-service/troubleshoot-intermittent-outbound-connection-errors#avoiding-the-problem

Observed Behaviour

The typescript compiler is complaining that:

Argument of type '{ agent: HttpAgents; }' is not assignable to parameter of type 'OmitStrict<RequestInit, "method">'. Object literal may only specify known properties, and 'agent' does not exist in type 'OmitStrict<RequestInit, "method">'

Expected Behaviour

The getPhotos and photos.get accept and use the agent parameter.

PhilHannent avatar Sep 12 '21 20:09 PhilHannent

How do you do this when you use fetch? The functions exported by this package just forward the options through to fetch.

The agent property doesn't seem to exist when we use fetch:

fetch('https://httpbin.org/get', { agent: {} })

https://www.typescriptlang.org/play?#code/GYUwLgxgFgFA5FMYAOBnAXAek4lAjASwDsA6AewCcBzTK8OAGgAIBvJgQzqLHVYF8mfAJRA

OliverJAsh avatar Sep 13 '21 09:09 OliverJAsh