Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CodingMarkus opened this issue Nov 28, 2024 · 2 comments
Open

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

CodingMarkus opened this issue Nov 28, 2024 · 2 comments
Labels
bug Something isn't working types An issue with TypeScript types

Comments

@CodingMarkus
Copy link

CodingMarkus commented Nov 28, 2024

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"
	]
@CodingMarkus CodingMarkus added bug Something isn't working needs triage labels Nov 28, 2024
@RiskyMH RiskyMH added types An issue with TypeScript types and removed needs triage labels Nov 29, 2024
@Gobd
Copy link

Gobd commented Nov 29, 2024

This is the same issue yeah? #8761

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

@CodingMarkus
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working types An issue with TypeScript types
Projects
None yet
Development

No branches or pull requests

3 participants