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 98 forks source link

Why can't insertion enum type to createStandardAction #160

Closed NoMoreViolence closed 5 years ago

NoMoreViolence commented 5 years ago

First of all checkout our gitter channel: https://gitter.im/react-redux-typescript-guide/typesafe-actions

Then please use Stack Overflow or other resources for help resolving your specific use-cases.

The only exceptions to use issue tracker for questions would be for some unusual "special cases".

I am using this library with react. (create-reactapp) I don't know why can't insertion enum type to createStandartAction

enum UserActionTypes { LOGIN = 'LOGIN' };

interface LoginPayload { aa: string; bb: string; };

// ERROR in create react app const loginAction = createStandardAction(UserActionTypes.LOGIN)();

piotrwitek commented 5 years ago

Hey @NoMoreViolence, please provide detailed error and minimal reproduction repository only then I'll be able to help you

NoMoreViolence commented 5 years ago

@piotrwitek

import { createStandardAction } from 'typesafe-actions';

enum UserActionTypes {
  LOGIN = 'LOGIN'
}

export interface LoginPayload {
  email: string;
  password: string;
}

// ERROR
export const userActions = {
  login: createStandardAction(UserActionTypes.LOGIN)<LoginPayload>(),
}

// WORKED
export const userActions = {
  login: createStandardAction('LOGIN')<LoginPayload>(),
}

TypeError: Cannot read property 'LOGIN' of undefined

in create react app compiler

piotrwitek commented 5 years ago

I don't think it's related to typesafe-actions. Have you used a debugger to check UserActionTypes value?

NoMoreViolence commented 5 years ago

You were right, It's about typescript compile, I will close this issue.