oven-sh / bun

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

@types/bun conflicts with @types/node breaking tsc #15481

Open CodingMarkus opened 4 days ago

CodingMarkus commented 4 days ago

What version of Bun is running?

1.1.37

What platform is your computer?

Darwin 23.6.0 arm64 arm

What steps can reproduce the bug?

bun install -d @types/bun

is all that is required to make the project incompatible with tsc.

What is the expected behavior?

tsc should still work, after all I just installed the bun types to the project.

What do you see instead?

tsc --emitDeclarationOnly results in:

node_modules/@types/node/globals.d.ts:370:14 - error TS2300: Duplicate identifier 'fetch'.

370     function fetch(
                 ~~~~~

  node_modules/bun-types/globals.d.ts:1037:6
    1037  var fetch: Fetch;
              ~~~~~
    'fetch' was also declared here.

node_modules/@types/node/module.d.ts:283:13 - error TS2687: All declarations of 'dirname' must have identical modifiers.

283             dirname: string;
                ~~~~~~~

node_modules/@types/node/module.d.ts:289:13 - error TS2687: All declarations of 'filename' must have identical modifiers.

289             filename: string;
                ~~~~~~~~

node_modules/bun-types/bun.d.ts:117:8 - error TS2420: Class 'ShellError' incorrectly implements interface 'ShellOutput'.
  Property 'bytes' is missing in type 'ShellError' but required in type 'ShellOutput'.

117  class ShellError extends Error implements ShellOutput {
           ~~~~~~~~~~

  node_modules/bun-types/bun.d.ts:434:3
    434   bytes(): Uint8Array;
          ~~~~~~~~~~~~~~~~~~~~
    'bytes' is declared here.

node_modules/bun-types/globals.d.ts:1037:6 - error TS2300: Duplicate identifier 'fetch'.

1037  var fetch: Fetch;
          ~~~~~

  ../../../../../../../opt/local/lib/node_modules/typescript/lib/lib.dom.d.ts:28148:18
    28148 declare function fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
                           ~~~~~
    'fetch' was also declared here.
  node_modules/@types/node/globals.d.ts:370:14
    370     function fetch(
                     ~~~~~
    and here.

node_modules/bun-types/globals.d.ts:1947:12 - error TS2687: All declarations of 'dirname' must have identical modifiers.

1947   readonly dirname: string;
                ~~~~~~~

node_modules/bun-types/globals.d.ts:1950:12 - error TS2687: All declarations of 'filename' must have identical modifiers.

1950   readonly filename: string;
                ~~~~~~~~

node_modules/bun-types/overrides.d.ts:3:29 - error TS2305: Module '"bun"' has no exported member 'PathLike'.

3 import type { BunFile, Env, PathLike } from "bun";
                              ~~~~~~~~

../../../../../../../opt/local/lib/node_modules/typescript/lib/lib.dom.d.ts:15520:11 - error TS2430: Interface 'MessageEvent<T>' incorrectly extends interface 'Bun.MessageEvent<T>'.
  Types of property 'ports' are incompatible.
    Type 'readonly MessagePort[]' is not assignable to type 'readonly import("worker_threads").MessagePort[]'.
      Type 'MessagePort' is missing the following properties from type 'MessagePort': ref, unref, addListener, emit, and 13 more.

15520 interface MessageEvent<T = any> extends Event {
                ~~~~~~~~~~~~

../../../../../../../opt/local/lib/node_modules/typescript/lib/lib.dom.d.ts:25534:11 - error TS2430: Interface 'WebSocket' incorrectly extends interface 'import("/Library/Automount/Internal/Repositories/equinux/Other/eqcrypt/node_modules/@types/ws/index").WebSocket'.
  Types of property 'binaryType' are incompatible.
    Type 'BinaryType' is not assignable to type '"arraybuffer" | "nodebuffer" | "fragments"'.
      Type '"blob"' is not assignable to type '"arraybuffer" | "nodebuffer" | "fragments"'.

25534 interface WebSocket extends EventTarget {
                ~~~~~~~~~

../../../../../../../opt/local/lib/node_modules/typescript/lib/lib.dom.d.ts:28148:18 - error TS2300: Duplicate identifier 'fetch'.

28148 declare function fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
                       ~~~~~

  node_modules/bun-types/globals.d.ts:1037:6
    1037  var fetch: Fetch;
              ~~~~~
    'fetch' was also declared here.

Found 11 errors in 6 files.

Errors  Files
     1  node_modules/@types/node/globals.d.ts:370
     2  node_modules/@types/node/module.d.ts:283
     1  node_modules/bun-types/bun.d.ts:117
     3  node_modules/bun-types/globals.d.ts:1037
     1  node_modules/bun-types/overrides.d.ts:3
     3  ../../../../../../../opt/local/lib/node_modules/typescript/lib/lib.dom.d.ts:15520

Additional information

I didn't install anything else, it was bun who decided to install both, @types/bun and @types/node and these two are incompatible with each other.

And yes, my tsconfig.json excludes all modules:

    "include": [
        "src/*.ts",
    ],
    "exclude": [
        "node_modules"
    ]
Gobd commented 3 days ago

This is the same issue yeah? https://github.com/oven-sh/bun/issues/8761

Your tsconfig must have "skipLibCheck": true and it'll work.

CodingMarkus commented 10 hours ago

Not sure. I was searching for the conflicting symbols and that other issue is about different symbols conflicting. I use none of these symbols myself but they could be used by my one and only dependency other than bun itself (@types/emscripten). The issue that there are conflicts between both type-packages is the same.

I wouldn't even care for tsc at all, I can bundle the code with bun but bun cannot create .d.ts files and without those, I have no type information when using my package within other TS projects.