Skip to content

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

Closed
@thisisamir98

Description

@thisisamir98

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions