redux-toolkit
redux-toolkit copied to clipboard
All createDraftSafeSelector in my app broken, with “No overload matches this call” when running Vite build after migrating from version 2.2.3
Hi Team
I just migrated to version 2.2.5 from version 2.2.3 and found that all my createDraftSafeSelector are throwing the above error, any idea ?
could you give an example of some code that's throwing the error, and the longer TS error message?
Hi EskiMojo,
Yes standard selectors
export const selectUsers = (state: RootState) => state.adminState.users; export const selectRoles = (state: RootState) => state.adminState.roles; export const selectEntitlements = (state: RootState) => state.adminState.entitlements;
and the used them into createDraftSafeSelector to create a unique piece of data, or computations, etc.
export const selectUsersSelector = createDraftSafeSelector( selectUsers, selectRoles, selectEntitlements, (originalUsers: User[], allRoles: Role[], allEntitlements: Entitlement[]) => { if (!originalUsers || !allRoles || !allEntitlements) return [];
return originalUsers?.reduce((acc, value) => {
....
}, [] as User[]);
} );
@acostaf Can you remove the type annotations in the last function and see if that resolves the error?
BTW this is the vscode/vite build error:
No overload matches this call. Overload 1 of 3, '(createSelectorArgs_0: (state: { authState: AuthState; ... 14 more ...; }) => User[] | undefined, createSelectorArgs_1: (state: { ...; }) => Role[] | undefined, createSelectorArgs_2: (state: { ...; }) => Entitlement[] | undefined, combiner: (resultFuncArgs_0: User[] | undefined, resultFuncArgs_1: Role[] | undefined, resultFuncArgs_2: Entitlement[] | undefined) => User[]): ((state: { ...; }) => User[]) & ... 2 more ... & { ...; }', gave the following error. Argument of type '(originalUsers: User[], allRoles: Role[], allEntitlements: Entitlement[]) => User[]' is not assignable to parameter of type '(resultFuncArgs_0: User[] | undefined, resultFuncArgs_1: Role[] | undefined, resultFuncArgs_2: Entitlement[] | undefined) => User[]'. Types of parameters 'originalUsers' and 'resultFuncArgs_0' are incompatible. Type 'User[] | undefined' is not assignable to type 'User[]'. Type 'undefined' is not assignable to type 'User[]'. Overload 2 of 3, '(createSelectorArgs_0: (state: { authState: AuthState; ... 14 more ...;}) => User[] | undefined, createSelectorArgs_1: (state: { ...; }) => Role[] | undefined, combiner: (resultFuncArgs_0: User[] | undefined, resultFuncArgs_1: Role[] | undefined) => Entitlement[] | undefined, createSelectorOptions: { ...; }): ((state: { ...; }) => Entitlement[] | undefined) & ... 2 more ... & { ...; }', gave the following error. Argument of type '(state: RootState) => Entitlement[] | undefined' is not assignable to parameter of type '(resultFuncArgs_0: User[] | undefined, resultFuncArgs_1: Role[] | undefined) => Entitlement[] | undefined'. Types of parameters 'state' and 'resultFuncArgs_0' are incompatible. Type 'User[] | undefined' is not assignable to type '{ authState: AuthState; ... 14 more ...;}'. Type 'undefined' is not assignable to type '{ authState: AuthState; ... 14 more ...; }'.ts(2769)
@acostaf Can you remove the type annotations in the last function and see if that resolves the error?
@aryaemami59 seem that removing the typing fixes the issue, I will try with the another 45 items throwing the error and report back, thanks for your help.
Do you know why is that the case?
Best Regards
AA
@acostaf Well from looking at it in first glance, it seems like selectUsers returns User[] | undefined, so when you explicitly annotate the result function's parameter as originalUsers: User[], that makes TypeScript unhappy because the types mismatch. Going forward, I recommend annotating as little as possible, the types in this library are designed in such a way that you're rarely going to need to annotate the types. Most types should be inferred from usage. Hope that helps.