mobxjs / mobx

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

Types for `.values()`, `.keys()`, and `.entries()` for `ObservableMap<K, V>` broke in 6.13.5 #3963

Closed Nokel81 closed 1 week ago

Nokel81 commented 1 week ago

Intended outcome:

The following code should pass type check:

const map = observable.map<string, string>();
const getFirstValue = (): string => Array.from(map.values())[0];

Actual outcome:

The line const getFirstValue = (): string => Array.from(map.values())[0]; has the following type error Type 'unknown' is not assignable to type 'string'. ts(2322)

Versions

mobx: 6.13.5 typescript: 4.9.5

mweststrate commented 1 week ago

could you add a codesandbox or similar to demonstrate the issue, against the latest typescript version? Note that we don't maintain compatibility with older TS versions, so you might need to upgrade first to 5.6.3. to see if the problem persists.

Nokel81 commented 1 week ago

Oh okay that is probably the problem then since I see you are now using the MapIterator type which was introduced in 5.6