Open JoShMiQueL opened 2 months ago
This workaround works, atleast for me
const response = await fetch("https://example-web.com/", {
method: "GET",
proxy: "http://your-proxy-url:port",
} as FetchRequestInit); // <-- Workaround
probably related in these two .d.ts
files
https://github.com/oven-sh/bun/blob/3d68a9483fbb69b7ac4dd9c686658ec14a6674e4/packages/bun-types/globals.d.ts#L929-L931
https://github.com/oven-sh/bun/blob/3d68a9483fbb69b7ac4dd9c686658ec14a6674e4/packages/bun-types/bun.d.ts#L3173-L3175
Thanks for the workaround! It works great. I also came up with a temporary solution to fix the editor issue by creating a .d.ts
file. Here's what I added:
// bun-fetch.d.ts
interface RequestInit {
proxy?: string;
verbose?: boolean;
}
This resolves the type error in the code editor for now.
There is another possibility of VSCode inferring wrong type due to TypeScript extension.
/opt/vscodium-bin/resources/app/extensions/node_modules/typescript/lib/lib.dom.d.ts
declare function fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
There is no method to influence it from bun, it can be avoided by clearly using only Bun's fetch.
Either with imports
import { fetch } from 'bun';
or with Bun prefix
const res = await Bun.fetch(...);
What version of Bun is running?
1.1.27+267afa293
What platform is your computer?
Microsoft Windows NT 10.0.22631.0 x64
What steps can reproduce the bug?
fetch
to make a request, including aproxy
property in theRequestInit
object.request().then(console.log).catch(console.error);
Despite this, the code runs without any issues when compiled and executed with Bun.js.
Additional information
No response