mobxjs / mobx

Simple, scalable state management.
http://mobx.js.org
MIT License
27.59k stars 1.78k forks source link

Typescript 5.6.x compatibility with ObservableSet and Observable Map #3927

Closed ymor closed 1 month ago

ymor commented 2 months ago

Intended outcome: ObservableMap should implement Map correctly and ObservableSet should implement Set correctly

Actual outcome:

Type 'ObservableMap<unknown, unknown>' is not assignable to type 'Map<unknown, unknown>'.
  The types returned by 'entries()' are incompatible between these types.
    Type 'IterableIterator<IMapEntry<unknown, unknown>>' is missing the following properties from type 'MapIterator<[unknown, unknown]>': map, filter, take, drop, and 9 more.
Type 'ObservableSet<unknown>' is not assignable to type 'Set<unknown>'.
  The types returned by 'entries()' are incompatible between these types.
    Type 'IterableIterator<[unknown, unknown]>' is missing the following properties from type 'SetIterator<[unknown, unknown]>': map, filter, take, drop, and 9 more.

How to reproduce the issue: https://www.typescriptlang.org/play/?target=99&ts=5.6.2#code/JYWwDg9gTgLgBAbzgeQEYGcCmUBuBDVAG0wFk8wAaFDbfIzAZU3gF84AzKCEOAchAioAHrwDcAKHEBjCADt08AcLJgAXHBUAeAK6yA1rIgB3WVV0HjsgHxwAvHFmYj1LLgLEVACgCUE6XIU4JSEmGHVQnX1DExt7R2c0VzpiUJ8JIA

Seems this might be relevant https://devblogs.microsoft.com/typescript/announcing-typescript-5-6/#iterator-helper-methods

No errors in Typescript 5.5.x

Versions mobx@6.13.2

Weffe commented 2 months ago

Just ran into this issue too. I think we need to update ObservableMap to match the new structure for .entries() with the new iterator helpers.

tonyraoul commented 1 month ago

Started working on a potential fix here keen for your feedback.