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

Argument of type 'AsyncThunkAction<{ id: number; }, void, AsyncThunkConfig>' is not assignable to parameter of type 'UnknownAction'. #4299

Closed
seafronthu opened this issue Mar 25, 2024 · 4 comments

Comments

@seafronthu
Copy link

          @EskiMojo14 I made a [demo](https://stackblitz.com/edit/stackblitz-starters-vbgz2h?file=src%2FApp.tsx), it does not work after defining the typed hooks.

Originally posted by @mrdulin in #4032 (comment)

@seafronthu
Copy link
Author

seafronthu commented Mar 25, 2024

This issue also exists in vscode.

const initialState: StateINF = {
  selectedTabId: 0,
  isDragging: false,
  value: []
}
export const addTab = createAsyncThunk('tabs/addTab1', async (): Promise<{ id: number }> => {
  return {
    id: 1
  }
})
const tabsSlice = createSlice({
  name: 'tabs',
  initialState,
  reducers: {
    // addTab(state, action: { payload: { id: number; url: string } }) {
    //   state.value = [...state.value, action.payload]
    // },
    changeTab(state) {
      state.value = []
    },
    delTab(state) {
      state.value = []
    }
  },
  extraReducers(builder) {
    builder.addCase(addTab.fulfilled, (state, action: PayloadAction<{ id: number }>) => {
      console.log(state, action)
    })
  }
})
export const useTabsSelector = () =>
  useSelector<{ tabs: StateINF }>((state) => state.tabs) as StateINF
export const { changeTab, delTab } = tabsSlice.actions
export const useAddTabDispatch = () => {
  const dispatch = useDispatch()
  return () => dispatch(addTab())
}
export default tabsSlice

image
image
version: "@reduxjs/toolkit": "^2.2.2" "react-redux": "^9.1.0"

@seafronthu seafronthu changed the title @EskiMojo14 I made a [demo](https://stackblitz.com/edit/stackblitz-starters-vbgz2h?file=src%2FApp.tsx), it does not work after defining the typed hooks. Argument of type 'AsyncThunkAction<{ id: number; }, void, AsyncThunkConfig>' is not assignable to parameter of type 'UnknownAction'. Mar 25, 2024
@iliapnmrv
Copy link

hey! any updates on this?

@seafronthu
Copy link
Author

hey! any updates on this?

"react-redux": "^9.1.0"
"@reduxjs/toolkit": "^2.2.2"
"@types/react": "^18.2.47"
"@types/react-dom": "^18.2.18"
"typescript": "^5.4.3"
I don't know what caused it, it's too uncomfortable.

@EskiMojo14
Copy link
Collaborator

Please follow our standard Typescript setup, you shouldn't be annotating a type on your store and you should be using pre-typed versions of the hooks.

@EskiMojo14 EskiMojo14 closed this as not planned Won't fix, can't repro, duplicate, stale Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants