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

Interface 'TypedDOMStringList<T>' incorrectly extends interface 'DOMStringList' #327

Open
thisisamir98 opened this issue Oct 11, 2024 · 1 comment

Comments

@thisisamir98
Copy link

trying to build this library with typescript version 5.0.4 I get this error:

node_modules/idb/build/entry.d.ts:121:18 - error TS2430: Interface 'TypedDOMStringList<T>' incorrectly extends interface 'DOMStringList'.
  The types returned by '[Symbol.iterator]()' are incompatible between these types.
    Type 'IterableIterator<T>' is missing the following properties from type 'ArrayIterator<string>': map, filter, take, drop, and 9 more.

121 export interface TypedDOMStringList<T extends string> extends DOMStringList {
                     ~~~~~~~~~~~~~~~~~~


Found 1 error in node_modules/idb/build/entry.d.ts:121

After some investigations I found out in the newer versions of javascript the type for iteration on DOMStringList has been officially added.

https://github.com/microsoft/TypeScript/blob/main/src/lib/dom.iterable.generated.d.ts#L80-L82

interface DOMStringList {
    [Symbol.iterator](): ArrayIterator<string>;
}

now updating

export interface TypedDOMStringList<T extends string> extends DOMStringList {
  contains(string: T): boolean;
  item(index: number): T | null;
  [index: number]: T;
  [Symbol.iterator](): IterableIterator<T>;
}

to

export interface TypedDOMStringList<T extends string> extends DOMStringList {
  contains(string: T): boolean;
  item(index: number): T | null;
  [index: number]: T;
  [Symbol.iterator](): ArrayIterator<string>;
}

breaks your library because typescript version 4.8.3 and it does not have ArrayIterator type.

Trying to fix it I found out that removing this line:

https://github.com/jakearchibald/idb/blob/main/src/entry.ts#L261

  [Symbol.iterator](): IterableIterator<T>;

does not break your library and i'm still able to build it successfully,

Could you investigate this? if it's possible I can open a PR to remove that line.

@jimtendo
Copy link

jimtendo commented Nov 3, 2024

I have also hit this issue.

For me, downgrading Typescript to 5.5.4 seems to have worked, so I suspect the amended interface is added from V5.6 upwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants