Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading from version 2.0.1 to 2.1.0 or 2.2.0 breaks vite build with TS (TS7006) errors #4200

Closed
acostaf opened this issue Feb 14, 2024 · 17 comments · Fixed by #4400, KenTandrian/ztm-robofriends#8 or KenTandrian/ztm-robofriends#9 · May be fixed by rajanjha9235/mega-blog#1 or aswanthchandran0/User-Management#3

Comments

@acostaf
Copy link

acostaf commented Feb 14, 2024

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?

@EskiMojo14
Copy link
Collaborator

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

@acostaf
Copy link
Author

acostaf commented Feb 14, 2024

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
Copy link
Author

acostaf commented Feb 14, 2024

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

@EskiMojo14
Copy link
Collaborator

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

@acostaf
Copy link
Author

acostaf commented Feb 14, 2024

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

@EskiMojo14
Copy link
Collaborator

could you show how you're using it?

@acostaf
Copy link
Author

acostaf commented Feb 14, 2024

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

@EskiMojo14
Copy link
Collaborator

image

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

@acostaf
Copy link
Author

acostaf commented Feb 14, 2024

5.3.3

@EskiMojo14
Copy link
Collaborator

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

@AlbericoD
Copy link

AlbericoD commented Feb 21, 2024

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

@rjgotten
Copy link

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.

@alexdunae
Copy link

I had a similar error

node_modules/@reduxjs/toolkit/dist/createDraftSafeSelector.d.ts:10:47 - error TS2707: Generic type 'CreateSelectorFunction<MemoizeFunction, ArgsMemoizeFunction>' requires between 0 and 2 type arguments.

10 export declare const createDraftSafeSelector: import("reselect").CreateSelectorFunction<typeof weakMapMemoize, typeof weakMapMemoize, any>;

and was able to fix it by updating the reselect dependency (from v5.0.1 to 5.1.0 in my case).

Similar to @AlbericoD I just removed and re-added rtk...

yarn remove @reduxjs/toolkit
yarn add @reduxjs/toolkit

@aryaemami59
Copy link
Contributor

aryaemami59 commented May 8, 2024

I think the issue here is that the new createDraftSafeSelector.withTypes() is derived from createSelector.withTypes() which is a feature that was added in reselect v5.1.0 but reselect is listed as a dependency of RTK with the version of ^5.0.1 so if the installed version of reselect is 5.0.1 and not 5.1.0 we get this type error and it goes away once we bump reselect to 5.1.0. I think we might have to update the dependency version of reselect to 5.1.0 in RTK since the .withTypes() feature of createDraftSafeSelector comes directly from reselect v5.1.0. @EskiMojo14 I can put up a PR to fix it tomorrow if you want.

@markerikson
Copy link
Collaborator

Ah, yes, we should definitely do that now!

@aryaemami59
Copy link
Contributor

aryaemami59 commented May 8, 2024

@markerikson Yessirrr. #4400.

@markerikson
Copy link
Collaborator

Out in 2.2.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment