oven-sh / bun

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

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

Open lgarron opened 7 months ago

lgarron commented 7 months ago

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;
                        ~~~~~~~~~
mangs commented 7 months ago

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

charlzyx commented 6 months ago

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 commented 4 months ago

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 commented 4 months ago

Same issues as well

yolmcore commented 4 months ago

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

KatFishSnake commented 4 months ago

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

cc @Jarred-Sumner

dphasst17 commented 4 months ago

Ảnh chụp màn hình 2024-05-14 140408 I also got the same error and I edited tsconfig.json like this { "compilerOptions": { "target": "es6", "module": "commonjs", "outDir": "./dist", "strict": true, "esModuleInterop": true, "sourceMap": true, "baseUrl": "./src", "types":[] // you can list the types you want to use here }, "include": ["src/**/*.ts"], "exclude": [ "node_modules", "node_modules/bun-types/globals.d.ts", "node_modules/bun-types/overrides.d.ts", "node_modules/typescript/lib/lib.dom.d.ts", "node_modules/@types/node/module.d.ts" ] } Then I rebuilt it and it didn't have the above error anymore

polRk commented 3 months ago

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
piscopancer commented 2 months ago

still a bug image

magick93 commented 1 month ago

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 commented 3 weeks ago

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

Joeghanoe commented 2 weeks ago

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