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
Can't set fetch agent #186
Comments
For now you can workaround this using a type assertion, although it's far from ideal: import nodeFetch from 'node-fetch'
import { InitParams } from 'unsplash-js/dist/helpers/request';
const params: InitParams ={
accessKey: "abc",
fetch: nodeFetch as unknown as typeof fetch
} This boils down to the fact that import nodeFetch from 'node-fetch'
/*
Type '(url: RequestInfo, init?: RequestInit) => Promise<Response>' is not assignable to type '(input: RequestInfo, init?: RequestInit) => Promise<Response>'.
Types of parameters 'url' and 'input' are incompatible.
Type 'RequestInfo' is not assignable to type 'import("/Users/oliverash/Development/unsplash-js-test/node_modules/node-fetch/@types/index").RequestInfo'.
Type 'Request' is not assignable to type 'RequestInfo'.
Type 'Request' is missing the following properties from type 'Request': size, buffer
*/
const myFetch: typeof fetch = nodeFetch;
The TS project needs to be configured to remove the Once that is fixed we should be able to do this: import * as nodeFetch from 'node-fetch'
import { InitParams } from 'unsplash-js/dist/helpers/request';
declare global {
var fetch: typeof nodeFetch.default;
type RequestInit = nodeFetch.RequestInit;
type Response = nodeFetch.Response;
}
const params: InitParams ={
accessKey: "abc",
fetch: nodeFetch.default
} |
Closing as it's not an issue with this library as per the comment above. |
Steps to Reproduce
Observed Behaviour
Types of parameters 'url' and 'input' are incompatible.
Type 'RequestInfo' is not assignable to type 'import("c:/Users/1144102435/Documents/Github/menupp-next/functions/node_modules/node-fetch/@types/index").RequestInfo'.
Type 'Request' is not assignable to type 'RequestInfo'.
Type 'Request' is missing the following properties from type 'Request': size, bufferts(2322)
request.d.ts(25, 5): The expected type comes from property 'fetch' which is declared here on type 'InitParams'
Expected Behaviour
Technical Notes
The text was updated successfully, but these errors were encountered: