You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, when I define a selector I want it to return the type without the Readonly modifier, so it's less verbose. Currently I do it with type casting like this:
import { createSelector } from 'reselect';
const selector = createSelector(state, (data) => data as MyType)
How do I do this without type casting the selector?
The text was updated successfully, but these errors were encountered:
it's not possible without casting - though i'd argue that it would make sense to keep the readonly modifier as you're not meant to modify data that comes out of a selector.
even though you've selected it with a selector, it's still redux state, and still should be immutable. mutating state leads to unexpected behaviour, which is why Redux Toolkit uses Immer to actually freeze the state (meaning an error is thrown if mutation is attempted) and includes a middleware to track attempted mutations.
Redux state is supposed to be immutable, so I've defined the state in my reducers like this
However, when I define a selector I want it to return the type without the
Readonly
modifier, so it's less verbose. Currently I do it with type casting like this:How do I do this without type casting the selector?
The text was updated successfully, but these errors were encountered: