redux-toolkit
redux-toolkit copied to clipboard
Upgrading from version 2.0.1 to 2.1.0 or 2.2.0 breaks vite build with TS (TS7006) errors
Hi Team
I just upgraded to version 2.2.0 and the change creates those this really weird issue, I am not changing anything on my tsconfig and eslinyrc and suddenly running vite build throws more than 600 implicit any type
Have anyone seen these before?
could you give an example of a piece of code which now errors?
const user = useAppSelector(selectedUser)
user?.uid used to work properly not errors but now the new versions says that user is any but the selector was created from a proper type.
Funny enough the selector is now returning unknown, which force the error on build
any chance you could put together a reproduction in typescript playground, codesandbox or a repo? none of our tests broke 😕
Actually I think the issue is coming from createDrafSafeSelector the function does not detect the original type returning any or unknown
could you show how you're using it?
Sorry about no been able to provide a proper example, I am behind a proxy so cannot copy and paste the real code.
store/Index.ts
const selectOriginalThing = (state: Rootstate) => state.myState.thing; (thing is properly typed as Type? from slice)
export const selectThing = createDraftSafeSelector(selectOriginalThing, (thing) (here is the type error, thing is now “any” instead of inferring type from selectOriginalThing
seems to be working in a playground - what typescript version are you using?
5.3.3
not sure what to suggest at this point then, sorry - without a replication i can't really look into it further
I had the same issue, I removed the package and then deleted node_modules, after which I installed the package again and it worked
The problem is probably that you have a store slice which use a strongly typed app-specific dispatch. To create a type for that app-specific dispatch, you need the fully constructed store. To craete the fully constructed store, you need all the slices. To make that one slice, you need the app-specific dispatch.
Things tend to become, literally, a bit loopy in those type of scenarios unless you very, very carefully order your imports in meticulous ways and ensure that type-only references are imported with import type
.