Skip to content

Type issue with union arguments for slice actions #142

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

Closed
pdobrev opened this issue May 9, 2019 · 2 comments
Closed

Type issue with union arguments for slice actions #142

pdobrev opened this issue May 9, 2019 · 2 comments

Comments

@pdobrev
Copy link

pdobrev commented May 9, 2019

We've been having issues upgrading TypeScript to 3.4 in a project that uses redux-starter-kit, so I gave v0.5.1 a try and noticed that the following code does not compile anymore:

import { createSlice, PayloadAction, configureStore } from 'redux-starter-kit';

type SceneID = 'main' | 'profile' | 'prefs';

const slice = createSlice({
  initialState: {
    scene: 'main' as SceneID,
  },
  reducers: {
    selectScene: (state, { payload }: PayloadAction<SceneID>) => {
      state.scene = payload;
    },
  },
});

const store = configureStore({
  reducer: slice.reducer,
});

store.dispatch(slice.actions.selectScene('profile'));

The error tsc gives is:

error TS2345: Argument of type '"profile"' is not assignable to parameter of type '"main" & "profile" & "prefs"'.
Type '"profile"' is not assignable to type '"main"'.

It seems that the argument type for the action was converted from a union to an intersection type.

The same code works with redux-starter-kit 0.4.3, but that one has other typing issues that prevent us from upgrading to TypeScript 3.4.

@pdobrev
Copy link
Author

pdobrev commented May 9, 2019

It seems that there is already a PR on this topic: #138

@markerikson
Copy link
Collaborator

Just merged #138 , so closing this.

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

2 participants