dfinity / agent-js

A collection of libraries and tools for building software around the Internet Computer, in JavaScript.

Home Page:https://agent-js.icp.xyz

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HttpAgent fetch declaration

peterpeterparker opened this issue · comments

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

Capture d’écran 2023-04-10 à 13 07 04

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?

Closing due to inactivity