redux-toolkit icon indicating copy to clipboard operation
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

Open acostaf opened this issue 1 year ago • 12 comments

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?

acostaf avatar Feb 14 '24 14:02 acostaf

could you give an example of a piece of code which now errors?

EskiMojo14 avatar Feb 14 '24 14:02 EskiMojo14

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.

acostaf avatar Feb 14 '24 14:02 acostaf

Funny enough the selector is now returning unknown, which force the error on build

acostaf avatar Feb 14 '24 14:02 acostaf

any chance you could put together a reproduction in typescript playground, codesandbox or a repo? none of our tests broke 😕

EskiMojo14 avatar Feb 14 '24 14:02 EskiMojo14

Actually I think the issue is coming from createDrafSafeSelector the function does not detect the original type returning any or unknown

acostaf avatar Feb 14 '24 15:02 acostaf

could you show how you're using it?

EskiMojo14 avatar Feb 14 '24 15:02 EskiMojo14

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

acostaf avatar Feb 14 '24 15:02 acostaf

image

seems to be working in a playground - what typescript version are you using?

EskiMojo14 avatar Feb 14 '24 16:02 EskiMojo14

5.3.3

acostaf avatar Feb 14 '24 16:02 acostaf

not sure what to suggest at this point then, sorry - without a replication i can't really look into it further

EskiMojo14 avatar Feb 14 '24 16:02 EskiMojo14

I had the same issue, I removed the package and then deleted node_modules, after which I installed the package again and it worked

AlbericoD avatar Feb 21 '24 20:02 AlbericoD

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.

rjgotten avatar Feb 21 '24 21:02 rjgotten