Closed
Description
Playing with some real-world repos using RTK and TS, to see what happens if I try to upgrade to a local 2.0-rc
+ build.
InvokeAI
- Code: https://github.com/invoke-ai/InvokeAI/tree/main/invokeai/frontend/web
- Usage: everything latest and greatest RTK. enhancers, middleware, RTKQ, listeners, entity adapters, even RTKQ "infinite queries" with entity adapters for the cache
Expected Issues
- Extensive use of
EntityState<T>
errors because it needs the second<Type, Id>
generic - use of
memoizeOptions: {equalityCheck}
Unexpected Issues
Listener inferred type wasThis is actually expected behavior per TS Bug found while testing the 2.0.0-beta.4 #3862 - TS has done this for a while, we now just infer asUnknownAction
, but worked okay when theisAnyOf()
was moved outsideUnknownAction
instead ofAnyAction
:
// boardIdSelected.ts
export const addBoardIdSelectedListener = () => {
startAppListening({
matcher: isAnyOf(boardIdSelected, galleryViewChanged),
effect: async (
action,
{ getState, dispatch, condition, cancelActiveListeners }
) => {
Apparently we need to haveconfigureStore()
has TS errors whenenhancers
is provided, andmiddleware
returns more than one middleware entry in the tuple. (Something about a tuple size mismatch, maybe? https://stackoverflow.com/questions/64308563/source-has-x-elements-but-target-allows-only-1 )middleware
declared beforeconfigureStore
, so that we can infer the type ofgetDefaultEnhancers
correctly. 🧙
export const store = configureStore({
reducer: rememberedRootReducer,
enhancers: (getDefaultEnhancers) => {
// Edited - this was originally `existingEnhancers.concat`
return getDefaultEnhancers()
.concat(
rememberEnhancer(window.localStorage, rememberedKeys, {
persistDebounce: 300,
serialize,
unserialize,
prefix: LOCALSTORAGE_PREFIX,
})
)
.concat(autoBatchEnhancer());
},
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
serializableCheck: false,
immutableCheck: false,
})
.concat(api.middleware)
.concat(dynamicMiddlewares)
.prepend(listenerMiddleware.middleware),
Metadata
Metadata
Assignees
Labels
No labels