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 still conflicts with @types/node #8761

Open
lgarron opened this issue Feb 7, 2024 · 24 comments
Open

@types/bun still conflicts with @types/node #8761

lgarron opened this issue Feb 7, 2024 · 24 comments
Assignees
Labels
bug Something isn't working types An issue with TypeScript types

Comments

@lgarron
Copy link
Contributor

lgarron commented Feb 7, 2024

What version of Bun is running?

1.0.25+a8ff7be64

What platform is your computer?

Darwin 23.2.0 arm64 arm

What steps can reproduce the bug?

mkdir /tmp/bun-node-types && cd /tmp/bun-node-types
bun init --yes
bun add @types/node @types/bun typescript
echo "{}" > tsconfig.json # Remove `skipLibCheck`
bun x tsc

What is the expected behavior?

TypeScript runs successfully.

What do you see instead?

node_modules/typescript/lib/lib.dom.d.ts:8138:11 - error TS2430: Interface 'EventSource' incorrectly extends interface 'Bun.EventSource'.
  Types of property 'onerror' are incompatible.
    Type '(this: EventSource, ev: Event) => any' is not assignable to type '(this: Bun.EventSource, ev: Event) => any'.
      The 'this' types of each signature are incompatible.
        Type 'Bun.EventSource' is not assignable to type 'EventSource'.
          Types of property 'onmessage' are incompatible.
            Type '(this: Bun.EventSource, ev: Bun.MessageEvent<any>) => any' is not assignable to type '(this: EventSource, ev: MessageEvent<any>) => any'.
              Types of parameters 'ev' and 'ev' are incompatible.
                Type 'MessageEvent<any>' is not assignable to type 'Bun.MessageEvent<any>'.
                  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.

8138 interface EventSource extends EventTarget {
               ~~~~~~~~~~~

node_modules/typescript/lib/lib.dom.d.ts:15414: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[]'.

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

node_modules/typescript/lib/lib.dom.d.ts:25362:11 - error TS2430: Interface 'WebSocket' incorrectly extends interface 'import("/private/tmp/bun-node-types/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"'.

25362 interface WebSocket extends EventTarget {
                ~~~~~~~~~


Found 3 errors in the same file, starting at: node_modules/typescript/lib/lib.dom.d.ts:8138

Additional information

Also see:

This prevents me from using @types/bun in projects where @types/node is also needed. When I try to use @types/bun in cubing.js, I get additional conflicts:

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/types.d.ts:601:12 - error TS2687: All declarations of 'dirname' must have identical modifiers.

601   readonly dirname: string;
               ~~~~~~~

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

604   readonly filename: string;
               ~~~~~~~~

node_modules/bun-types/types.d.ts:1036:20 - error TS2694: Namespace 'WebSocket' has no exported member 'WebSocket'.

1036     : import("ws").WebSocket;
                        ~~~~~~~~~
@lgarron lgarron added the bug Something isn't working label Feb 7, 2024
@lgarron lgarron changed the title @types/node still conflicts with @types/bun @types/bun still conflicts with @types/node Feb 7, 2024
@paperdave paperdave added the types An issue with TypeScript types label Feb 7, 2024
@mangs
Copy link
Contributor

mangs commented Feb 9, 2024

Confirmed I'm seeing the same exact errors in my project too. Thank you for reporting.

@charlzyx
Copy link

charlzyx commented Mar 1, 2024

more info , fetch work bad, no lib.dom found.

image

but navigator seems ok

image

here is my config, bun version: 1.0.29

{
  "compilerOptions": {
    "target": "ES2020",
    "moduleDetection": "force",
    "lib": ["DOM", "DOM.Iterable", "ESNext"],
    "module": "ESNext",
    "jsx": "react-jsx",
    "strict": true,
    "skipLibCheck": true,
    "isolatedModules": true,
    "resolveJsonModule": true,
    "moduleResolution": "bundler",
    "useDefineForClassFields": true,
    "allowImportingTsExtensions": true,
    "verbatimModuleSyntax": true,
    "noEmit": true,
    "noFallthroughCasesInSwitch": true,
  },
  "include": ["src", "config", "plugins"]
}

package.json

{
  "devDependencies": {
    "@types/bun": "^1.0.8",
    "typescript": "^5.3.0"
  }
}

@gvelim
Copy link

gvelim commented Apr 20, 2024

Experiencing same problem when running bunx tsc index.ts with or without typescript module installed.

../../../../private/tmp/bunx-501-typescript@latest/node_modules/typescript/lib/lib.dom.d.ts:8183:11 - error TS2430: Interface 'EventSource' incorrectly extends interface 'Bun.EventSource'.
  Types of property 'onerror' are incompatible.
    Type '(this: EventSource, ev: Event) => any' is not assignable to type '(this: Bun.EventSource, ev: Event) => any'.
      The 'this' types of each signature are incompatible.
        Type 'Bun.EventSource' is not assignable to type 'EventSource'.
          Types of property 'onmessage' are incompatible.
            Type '(this: Bun.EventSource, ev: Bun.MessageEvent<any>) => any' is not assignable to type '(this: EventSource, ev: MessageEvent<any>) => any'.
              Types of parameters 'ev' and 'ev' are incompatible.
                Type 'MessageEvent<any>' is not assignable to type 'Bun.MessageEvent<any>'.
                  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.

8183 interface EventSource extends EventTarget {
               ~~~~~~~~~~~

../../../../private/tmp/bunx-501-typescript@latest/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[]'.

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

../../../../private/tmp/bunx-501-typescript@latest/node_modules/typescript/lib/lib.dom.d.ts:25534:11 - error TS2430: Interface 'WebSocket' incorrectly extends interface 'import("/Users/milev/development/js-pe/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 {
                ~~~~~~~~~

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/globals.d.ts:1917:12 - error TS2687: All declarations of 'dirname' must have identical modifiers.

1917   readonly dirname: string;
                ~~~~~~~

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

1920   readonly filename: string;
                ~~~~~~~~

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

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


Found 8 errors in 4 files.

Errors  Files
     3  ../../../../private/tmp/bunx-501-typescript@latest/node_modules/typescript/lib/lib.dom.d.ts:8183
     2  node_modules/@types/node/module.d.ts:283
     2  node_modules/bun-types/globals.d.ts:1917
     1  node_modules/bun-types/overrides.d.ts:3

Modules installed

bun pm ls --all                                                                                     
node_modules
├── @types/bun@1.1.0
├── @types/node@20.11.30
├── @types/ws@8.5.10
├── bun-types@1.1.0
└── undici-types@5.26.5
yarn info -A                                                                                        
├─ @types/bun@npm:1.1.0
│  ├─ Version: 1.1.0
│  │
│  └─ Dependencies
│     └─ bun-types@npm:1.1.0 → npm:1.1.0
│
└─ js-pe@workspace:.
   ├─ Version: 0.0.0
   │
   └─ Dependencies
      └─ @types/bun@npm:^1.1.0 → npm:1.1.0

@asleepace
Copy link

Same issues as well

@yolmcore
Copy link

yolmcore commented May 9, 2024

I got the error as well on Mac OS with @types/bun latest

@KatFishSnake
Copy link

Any workaround in a meantime? Would love to use bun:test 🙏

cc @Jarred-Sumner

@polRk
Copy link

polRk commented Jun 2, 2024

Also different type for URL. i cant use URL with fetch...

Argument of type URL is not assignable to parameter of type string | Request | URL

lgarron added a commit to lgarron/random-uint-below.js that referenced this issue Jun 6, 2024
This is a workaround for oven-sh/bun#8761 to allow our types to build.
@piscopancer
Copy link

still a bug
image

@magick93
Copy link

magick93 commented Aug 7, 2024

I'm getting the same issues with a project that doesnt even use bun but is part of a pnpm / turborepo project, which includes a project that uses bun.

Does anyone have a solution?

@michealroberts
Copy link

Same issues in a very basic TypeScript project with bun ...

@Joeghanoe
Copy link

Same issue here, unable to use bun:test because of this... :(

@cquasar
Copy link

cquasar commented Sep 23, 2024

Also having trouble with it

@lifenautjoe
Copy link

Still happening :-(

@Ollie1700
Copy link

Ollie1700 commented Oct 14, 2024

We migrated to Bun on an older project that still builds with tsc -b on the build scripts. Adding tests folder to exclude in tsconfig.json worked for us:

Scratch that... As long as it's installed in node_modules the build fails ☹️

@Numbers11

This comment has been minimized.

1 similar comment
@meftunca

This comment has been minimized.

@atbe

This comment has been minimized.

@AlexShkreba

This comment has been minimized.

@kravetsone
Copy link

just use skipLibCheck

kravetsone added a commit to kravetsone/bull-board that referenced this issue Nov 8, 2024
felixmosh pushed a commit to felixmosh/bull-board that referenced this issue Nov 12, 2024
* feat: add elysia adapter

* chore: use typings from dist and remove Promise

* chore: improve package and README

* chore: improve elysia example

* chore: use skipLibCheck (oven-sh/bun#8761)

* change: author at package

* chore: bumps
felixmosh pushed a commit to felixmosh/bull-board that referenced this issue Nov 13, 2024
* feat: add elysia adapter

* chore: use typings from dist and remove Promise

* chore: improve package and README

* chore: improve elysia example

* chore: use skipLibCheck (oven-sh/bun#8761)

* change: author at package

* chore: bumps

* chore: support top-level await in example

* chore: add docker-compose.redis for better testing

* chore: a lot of fixes

* chore: remove @elysiajs/static usage (switched to Bun.glob)

* chore: remove `@elysiajs/static` import and switch to `elysia` at example (in user project shouldnt break types)

* chore: add missing tsconfig

* chore: export

* chore: bumps
@lgarron
Copy link
Contributor Author

lgarron commented Nov 14, 2024

This issue has gotten more severe, as it seems TypeScript now ships with @types/node built-in. So this now reproduces even if you don't explicitly include @types/node in your project:

mkdir /tmp/bun-node-types && cd /tmp/bun-node-types
bun init --yes
bun add @types/bun typescript
echo "{}" > tsconfig.json # Remove `skipLibCheck`
bun x tsc

As using tsc for type-checking can be rather important, this makes it really painful to use bun for any non-trivial project. This is the kind of thing that would be an immediate deal-breaker for me if I wasn't already a fan of bun's other benefits.

@lgarron
Copy link
Contributor Author

lgarron commented Nov 14, 2024

This issue has gotten more severe, as it seems TypeScript now ships with @types/node built-in. So this now reproduces even if you don't explicitly include @types/node in your project:

Actually, it's now even worse than I thought. Even "types": ["@types/bun"] and "skipLibCheck": true fail to prevent the issue. So the repro is now just:

mkdir /tmp/bun-node-types && cd /tmp/bun-node-types
bun init --yes
bun add @types/bun typescript
bun x tsc

It is literally impossible to use the TypeScript compiler and bun in the same repo using the default configuration from bun init.

@Jarred-Sumner, @nektro: Apologies for the direct ping, but I'd really appreciate a signal about what bun plans to do about this. This is no longer possible to work around at the level of individual projects.

@alii
Copy link
Collaborator

alii commented Nov 22, 2024

@lgarron are you able to put together a small reproduction repo? Copying those commands exactly above but not seeing any errors from TypeScript.

@lgarron
Copy link
Contributor Author

lgarron commented Nov 22, 2024

@lgarron are you able to put together a small reproduction repo? Copying those commands exactly above but not seeing any errors from TypeScript.

Woah, it looks like that one is fixed with the latest versions!

But the original repro still holds:

mkdir /tmp/bun-node-types && cd /tmp/bun-node-types
bun init --yes
bun add @types/node @types/bun typescript
echo "{}" > tsconfig.json # Remove `skipLibCheck`
bun x tsc

Here's a snapshot in a repo: https://github.com/lgarron/bun-8761-repro-snapshot

@alii
Copy link
Collaborator

alii commented Nov 23, 2024

@lgarron Thanks very much for that, looking into this now

@alii alii self-assigned this Nov 23, 2024
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