-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Description
Bug Report
🔎 Search Terms
immutable map redux slice
🕗 Version & Regression Information
- This fails in some way in every version I tried, and I reviewed the FAQ for entries about
- The error changes between versions 3.7.5 and 3.8.3 (versions available on playground)
- 3.7.5 and prior can't infer the state type at all
- 3.8.3 and after infer it incorrectly
⏯ Playground Link
Playground link with relevant code
💻 Code
// "dependencies": {
// "@reduxjs/toolkit": "^1.6.1",
// "immutable": "^4.0.0-rc.14",
// "typescript": "next"
// }
import { Map } from 'immutable';
import { createSlice } from '@reduxjs/toolkit';
// This works as you'd expect in all versions
let myMap = Map<string, number>();
myMap = myMap.set('abc', 1);
myMap = myMap.deleteAll(['abc']);
console.log(myMap);
// In a slice though the type binds to the default Map type
export const testSlice = createSlice({
name: 'test',
initialState: {
stale: Map<string, number>(),
staleLast: 0,
},
reducers: {
// <=3.7.5 errors here: Parameter 'state' implicitly has an 'any' type.(7006)
test: (state) => {
// 3.8.3+: (property) stale: globalThis.Map<string, number>
// Type 'void' is not assignable to type 'Map<string, number>'.(2322)
state.stale = state.stale.clear();
// 3.8.3+: Property 'deleteAll' does not exist on type 'Map<string, number>'.(2339)
state.stale = state.stale.deleteAll(['test']);
},
},
});
export const { test } = testSlice.actions;
export default testSlice.reducer;🙁 Actual behavior
Typescript binds the wrong Map type, using the default DOM Map instead of the immutable Map declared. It definitely knows it a Map, it just gets the wrong one.
🙂 Expected behavior
That it would bind to the correct Map type.
Metadata
Metadata
Assignees
Labels
No labels