oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.26k stars 2.69k forks source link

fetch tls type error #13167

Open TomWeStartFires opened 1 month ago

TomWeStartFires commented 1 month ago

What version of Bun is running?

1.1.22-canary.96+df33f2b2a

What platform is your computer?

Linux 6.6.6-76060606-generic x86_64 x86_64

What steps can reproduce the bug?

Create a new bun project using bun init

Copy and paste the fetch tls example from bun docs https://bun.sh/docs/api/fetch

await fetch("https://example.com", {
  tls: {
    key: Bun.file("/path/to/key.pem"),
    cert: Bun.file("/path/to/cert.pem"),
    // ca: [Bun.file("/path/to/ca.pem")],
  },
});

What is the expected behavior?

Expected behavior is to have no type errors.

What do you see instead?

Type error on tls:

No overload matches this call.
  The last overload gave the following error.
    Object literal may only specify known properties, and 'tls' does not exist in type 'RequestInit'.ts(2769)
lib.dom.d.ts(28327, 18): The last overload is declared here.

image

image

Additional information

I believe this is an issue with DefinitelyTyped's bun types being behind in version. Looks like the last version merged with 1.1.17. Or possibly with the monorepo bun-types being incorrect.

https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/bun https://github.com/oven-sh/bun/tree/main/packages/bun-types

From the node_modules/bun-types/globals.d.ts

interface FetchRequestInit extends RequestInit {
  /**
      * Log the raw HTTP request & response to stdout. This API may be
      * removed in a future version of Bun without notice.
      * This is a custom property that is not part of the Fetch API specification.
      * It exists mostly as a debugging tool
      */
  verbose?: boolean;
  /**
      * Override http_proxy or HTTPS_PROXY
      * This is a custom property that is not part of the Fetch API specification.
      */
  proxy?: string;

  /**
      * Override the default TLS options
      */
  tls?: {
      rejectUnauthorized?: boolean | undefined; // Defaults to true
      checkServerIdentity?: any; // TODO: change `any` to `checkServerIdentity`
  };
}

As seen tls only has the two properties rejectUnauthorized and checkServerIdentity, and is missing key, cert, and ca .

ptrxyz commented 3 weeks ago

Seems the last version @types/bun that does not have this problem is 1.1.6; 1.1.7 and higher are broken.