bun icon indicating copy to clipboard operation
bun copied to clipboard

Mismatch `HeadersInit` type after using `import("undici-types").Headers`

Open br1anchen opened this issue 1 year ago • 2 comments

I am getting following error when I try to use bun-types >= 1.0.19:

Type '{ 'Content-Type'?: ContentType.Json | ContentType.UrlEncoded | ContentType.Text | undefined; length: number; toString(): string; toLocaleString(): string; pop(): [string, string] | undefined; push(...items: [string, string][]): number; concat(...items: ConcatArray<[string, string]>[]): [string, string][]; concat(...items: ([string, string] | ConcatArray<[string, string]>)[]): [string, string][]; join(separator?: string | undefined): string; reverse(): [string, string][]; shift(): [string, string] | undefined; slice(start?: number | undefined, end?: number | undefined): [string, string][]; sort(compareFn?: ((a: [string, string], b: [string, string]) => number) | undefined): [string, string][]; splice(start: number, deleteCount?: number | undefined): [string, string][]; splice(start: number, deleteCount: number, ...items: [string, string][]): [string, string][]; unshift(...items: [string, string][]): number; indexOf(searchElement: [string, string], fromIndex?: number | undefined): number; lastIndexOf(searchElement: [string, string], fromIndex?: number | undefined): number; every<S extends [string, string]>(predicate: (value: [string, string], index: number, array: [string, string][]) => value is S, thisArg?: any): this is S[]; every(predicate: (value: [string, string], index: number, array: [string, string][]) => unknown, thisArg?: any): boolean; some(predicate: (value: [string, string], index: number, array: [string, string][]) => unknown, thisArg?: any): boolean; forEach(callbackfn: (value: [string, string], index: number, array: [string, string][]) => void, thisArg?: any): void; map<U>(callbackfn: (value: [string, string], index: number, array: [string, string][]) => U, thisArg?: any): U[]; filter<S extends [string, string]>(predicate: (value: [string, string], index: number, array: [string, string][]) => value is S, thisArg?: any): S[]; filter(predicate: (value: [string, string], index: number, array: [string, string][]) => unknown, thisArg?: any): [string, string][]; reduce(callbackfn: (previousValue: [string, string], currentValue: [string, string], currentIndex: number, array: [string, string][]) => [string, string]): [string, string]; reduce(callbackfn: (previousValue: [string, string], currentValue: [string, string], currentIndex: number, array: [string, string][]) => [string, string], initialValue: [string, string]): [string, string]; reduce<U>(callbackfn: (previousValue: U, currentValue: [string, string], currentIndex: number, array: [string, string][]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: [string, string], currentValue: [string, string], currentIndex: number, array: [string, string][]) => [string, string]): [string, string]; reduceRight(callbackfn: (previousValue: [string, string], currentValue: [string, string], currentIndex: number, array: [string, string][]) => [string, string], initialValue: [string, string]): [string, string]; reduceRight<U>(callbackfn: (previousValue: U, currentValue: [string, string], currentIndex: number, array: [string, string][]) => U, initialValue: U): U; find<S extends [string, string]>(predicate: (value: [string, string], index: number, obj: [string, string][]) => value is S, thisArg?: any): S | undefined; find(predicate: (value: [string, string], index: number, obj: [string, string][]) => unknown, thisArg?: any): [string, string] | undefined; findIndex(predicate: (value: [string, string], index: number, obj: [string, string][]) => unknown, thisArg?: any): number; fill(value: [string, string], start?: number | undefined, end?: number | undefined): [string, string][]; copyWithin(target: number, start: number, end?: number | undefined): [string, string][]; entries(): IterableIterator<[number, [string, string]]>; keys(): IterableIterator<number>; values(): IterableIterator<[string, string]>; includes(searchElement: [string, string], fromIndex?: number | undefined): boolean; flatMap<U, This = undefined>(callback: (this: This, value: [string, string], index: number, array: [string, string][]) => U | readonly U[], thisArg?: This | undefined): U[]; flat<A, D extends number = 1>(this: A, depth?: D | undefined): FlatArray<A, D>[]; at(index: number): [string, string] | undefined; findLast<S extends [string, string]>(predicate: (value: [string, string], index: number, array: [string, string][]) => value is S, thisArg?: any): S | undefined; findLast(predicate: (value: [string, string], index: number, array: [string, string][]) => unknown, thisArg?: any): [string, string] | undefined; findLastIndex(predicate: (value: [string, string], index: number, array: [string, string][]) => unknown, thisArg?: any): number; toReversed(): [string, string][]; toSorted(compareFn?: ((a: [string, string], b: [string, string]) => number) | undefined): [string, string][]; toSpliced(start: number, deleteCount: number, ...items: [string, string][]): [string, string][]; toSpliced(start: number, deleteCount?: number | undefined): [string, string][]; with(index: number, value: [string, string]): [string, string][]; [Symbol.iterator](): IterableIterator<[string, string]>; [Symbol.unscopables]: { [x: number]: boolean | undefined; length?: boolean | undefined; toString?: boolean | undefined; toLocaleString?: boolean | undefined; pop?: boolean | undefined; push?: boolean | undefined; concat?: boolean | undefined; join?: boolean | undefined; reverse?: boolean | undefined; shift?: boolean | undefined; slice?: boolean | undefined; sort?: boolean | undefined; splice?: boolean | undefined; unshift?: boolean | undefined; indexOf?: boolean | undefined; lastIndexOf?: boolean | undefined; every?: boolean | undefined; some?: boolean | undefined; forEach?: boolean | undefined; map?: boolean | undefined; filter?: boolean | undefined; reduce?: boolean | undefined; reduceRight?: boolean | undefined; find?: boolean | undefined; findIndex?: boolean | undefined; fill?: boolean | undefined; copyWithin?: boolean | undefined; entries?: boolean | undefined; keys?: boolean | undefined; values?: boolean | undefined; includes?: boolean | undefined; flatMap?: boolean | undefined; flat?: boolean | undefined; at?: boolean | undefined; findLast?: boolean | undefined; findLastIndex?: boolean | undefined; toReversed?: boolean | undefined; toSorted?: boolean | undefined; toSpliced?: boolean | undefined; with?: boolean | undefined; [Symbol.iterator]?: boolean | undefined; readonly [Symbol.unscopables]?: boolean | undefined; }; } | { 'Content-Type'?: ContentType.Json | ContentType.UrlEncoded | ContentType.Text | undefined; } | { 'Content-Type'?: ContentType.Json | ContentType.UrlEncoded | ContentType.Text | undefined; append(name: string, value: string): void; delete(name: string): void; get(name: string): string | null; getSetCookie(): string[]; has(name: string): boolean; set(name: string, value: string): void; forEach(callbackfn: (value: string, key: string, parent: Headers) => void, thisArg?: any): void; entries(): IterableIterator<[string, string]>; keys(): IterableIterator<string>; values(): IterableIterator<string>; toJSON(): Record<string, string>; count: number; getAll(name: "set-cookie" | "Set-Cookie"): string[]; [Symbol.iterator](): IterableIterator<[string, string]>; prototype: Headers; }' is not assignable to type 'HeadersInit | undefined'.
  Type '{ 'Content-Type'?: ContentType.Json | ContentType.UrlEncoded | ContentType.Text | undefined; append(name: string, value: string): void; delete(name: string): void; get(name: string): string | null; getSetCookie(): string[]; has(name: string): boolean; set(name: string, value: string): void; forEach(callbackfn: (value: string, key: string, parent: Headers) => void, thisArg?: any): void; entries(): IterableIterator<[string, string]>; keys(): IterableIterator<string>; values(): IterableIterator<string>; toJSON(): Record<string, string>; count: number; getAll(name: "set-cookie" | "Set-Cookie"): string[]; [Symbol.iterator](): IterableIterator<[string, string]>; prototype: Headers; }' is not assignable to type 'HeadersInit | undefined'.
    Type '{ 'Content-Type'?: ContentType.Json | ContentType.UrlEncoded | ContentType.Text | undefined; append(name: string, value: string): void; delete(name: string): void; get(name: string): string | null; getSetCookie(): string[]; has(name: string): boolean; set(name: string, value: string): void; forEach(callbackfn: (value: string, key: string, parent: Headers) => void, thisArg?: any): void; entries(): IterableIterator<[string, string]>; keys(): IterableIterator<string>; values(): IterableIterator<string>; toJSON(): Record<string, string>; count: number; getAll(name: "set-cookie" | "Set-Cookie"): string[]; [Symbol.iterator](): IterableIterator<[string, string]>; prototype: Headers; }' is not assignable to type 'undefined'.

Which is missing prototype: Headers.

It seems like it is introduced by bun-types replaced internal typing definition of Headers to import("undici-types").Headers here.

Here is lib for tsconfig.json which we used in the project:

        "lib": ["DOM", "DOM.Iterable", "ESNext"],

br1anchen avatar Jan 10 '24 07:01 br1anchen

We have the same issue. Can't upgrade to @types/[email protected].

bjon avatar Jan 10 '24 19:01 bjon

same here

TiBianMod avatar Jan 13 '24 23:01 TiBianMod

Thanks for the report, are you still experiencing this? We've changed a fair bit of the types recently, there's a chance this got fixed.

alii avatar Mar 13 '25 15:03 alii

Hello @br1anchen. Please provide a minimal reproduction using a GitHub repository, Replit, CodeSandbox, or provide a bulleted list of commands to run that reproduce this issue. Issues marked with needs repro will be closed if they have no activity within 3 days.

github-actions[bot] avatar Mar 13 '25 15:03 github-actions[bot]

@alii Sorry for late report this back. As far as I can see this issue is resolved in our setup with "bun-types": "^1.1.43",.

br1anchen avatar Mar 14 '25 10:03 br1anchen

Sweet I'm glad to hear that! Thanks for closing.

alii avatar Mar 14 '25 14:03 alii