HttpAgent fetch declaration
peterpeterparker opened this issue · comments
David Dal Busco commented
Is your feature request related to a problem? Please describe.
When I use pass fetch
to create and HttpAgent
in a NodeJS context with TypeScript I get following error:
TS2322: Type '(url: URL | RequestInfo, init?: RequestInit | undefined) => Promise' is not assignable to type '(input: URL | RequestInfo, init?: RequestInit | undefined) => Promise'.
Code
import {HttpAgent} from "@dfinity/agent";
import fetch from 'node-fetch';
const icAgent = (identity) => {
return new HttpAgent({ identity, fetch, host: 'https://icp0.io' });
};
Stacktrace
TS2322: Type '(url: URL | RequestInfo, init?: RequestInit | undefined) => Promise<Response>' is not assignable to type '(input: URL | RequestInfo, init?: RequestInit | undefined) => Promise<Response>'. Types of parameters 'url' and 'input' are incompatible. Type 'URL | RequestInfo' is not assignable to type 'URL | import("/Users/daviddalbusco/projects/juno/observatory/functions/node_modules/node-fetch/@types/index").RequestInfo'. Type 'Request' is not assignable to type 'URL | RequestInfo'. Type 'Request' is missing the following properties from type 'Request': size, buffer
Kai Peacock commented
I've been recommending isomorphic-fetch
or using the built-in fetch from node >17. Is there a reason those solutions don't work for your use case?
Kai Peacock commented
Closing due to inactivity