yjs / yjs

Shared data types for building collaborative software
https://docs.yjs.dev
Other
17k stars 617 forks source link

Y.Map iterator typing info dosn't match implementation. #420

Closed cm226 closed 2 years ago

cm226 commented 2 years ago

Describe the bug I think that the typescript annotations for the iterator on the Y.Map type don't match what the function actually returns. The type for the iterator in map is:

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

The implementation of Y.Map does:

[Symbol.iterator] () {
    return this.entries()
}

entries has the type

IterableIterator<any>

which returns an Iterator of [key, value] array type.

I dont think these types match.

To Reproduce Can be seen by running

// create map of type Y.Map
for (const value of map) {
  // ts expects value to be of "MapType"
  // but at runtime its [key,value]
}

Expected behavior not sure what exactly should happen, but the typescript types should reflect the real type information.

Environment Information

Huly®: YJS-287

dmonad commented 2 years ago

Thank you @cm226! I adjusted the typing. In the next major release, I want to add proper typing information to the iterators. When I originally implemented this, I had problems with the Iterator typings and set everything to any.