-
-
Notifications
You must be signed in to change notification settings - Fork 99
Description
If I understand correctly, typesafe-actions v2.0 doesn't work well with @babel/plugin-transform-typescript.
I've been using @babel/plugin-transform-typescript in conjunction with react-app-rewired (via react-app-rewire-typescript-babel-preset so that I can use react-scripts from create-react-app rather than react-scripts-ts from create-react-app-typescript. I do this because I want to use all the upstream features in create-react-app that haven't made it to create-react-app-typescript yet.
I get a whole bunch of type errors in my IDE using [email protected] that I don't get when I try out your sample app. For example:
Creating actions like:
import {ActionsUnion, createStandardAction, getType} from "typesafe-actions";
const menuActions = {
openMenu: createStandardAction('menu/OPEN')<void>(),
closeMenu: createStandardAction('menu/CLOSE')<void>(),
};
type MenuActions = ActionsUnion<typeof menuActions>;
type RootAction = MenuActions | OtherActions;
type MenuState = {
readonly show: boolean,
}
const menuReducer = (state = {show: false}, action: RootAction): MenuState => {
switch (action.type) { // <---- one of the type errors (see below)
case getType(menuActions.openMenu):
return {show: true};
case getType(menuActions.closeMenu):
return {show: false};
default:
return state;
}
};Produces:
Property 'type' does not exist on type 'RootAction'.
Property 'type' does not exist on type '{ openMenu: B; closeMenu: B; }'.
I just asked a question in react-app-rewire-typescript-babel-preset to understand how this setup might differ from the one in your sample app. It seems the Babel TypeScript preset isn't using TypeScript at all and as a result there's a few language feature gotchas.
Can you help me determine if it's possible to use typesafe-actions v2.0 with @babel/plugin-transform-typescript rather than standard TypeScript compiler?