piotrwitek / typesafe-actions

Typesafe utilities for "action-creators" in Redux / Flux Architecture
https://codesandbox.io/s/github/piotrwitek/typesafe-actions/tree/master/codesandbox
MIT License
2.41k stars 99 forks source link

ActionType is always never #204

Closed antony2809 closed 4 years ago

antony2809 commented 4 years ago

I'm trying to follow the tutorial, and I don't know why when making de declaration of my type Actions, is always return never. So this doesn't allows me to use the helpers.

I have this file structure

constants.ts

export const LOGIN = '@authentication/LOGIN';
export const LOGGED_IN = '@authentication/LOGGED_IN';
export const LOGOUT = '@authentication/LOGOUT';

actions.ts

import { createAction } from 'typesafe-actions';
import { LOGIN } from './constants';

export const login = createAction(LOGIN, action => {
  return (email: string, password: string) => action({email, password});
});

reducer.ts

import { ActionType, getType } from 'typesafe-actions';
import * as actions from './auth.actions';

export type AuthenticationAction = ActionType<typeof authenticationActions>; // Here it's always of type never

I'm doing something wrong, because I couldn't find the solution for this.

Regards

piotrwitek commented 4 years ago

Hey @antony2809 Which version are you using v4 or v5?

antony2809 commented 4 years ago

V5

piotrwitek commented 4 years ago

Below usage is from v4:

export const login = createAction(LOGIN, action => {
  return (email: string, password: string) => action({email, password});
});

Please check the new temporary: v5.x.x API Docs

There is an announcement in the Readme:

Screen Shot 2019-10-29 at 9 53 15 PM

mitsuruog commented 4 years ago

@antony2809 I had the same issue just now. I guess you are on the tutorial V4. (V5 tutorial seems WIP) please try on V4, then the above issue will be gone. or check out the migration guide.