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

Object map style cannot use getType to match action in the createReducer #214

Open
cloudshadow opened this issue Nov 27, 2019 · 3 comments

Comments

@cloudshadow
Copy link

cloudshadow commented Nov 27, 2019

Description

When i use object map style to create reducer i find ts can not get the type of action and state.

Mandatory info

How to Reproduce

CodeSandbox Link

(PASTE HERE your codesandbox link)

No CodeSandbox Link

If no codesandbox, then please provide a full working code example below including actions, reducers and your custom types used in the example.

// this code is not work
export const reducer = createReducer<ITypeState, ITypeActions>(defaultTypeState, {
  [getType(rootAction.someActions.success)]: (state, action) =>
    produce(state, draft => {
      // todo
    })
});

// this code is work
export const reducer = createReducer<ITypeState, ITypeActions>(defaultTypeState, {
  ['Success']: (state, action) =>
    produce(state, draft => {
      // todo
    })
});

Expected behavior

when use getType function in object map style ts can get the correct type for action and state

Suggested solution(s)

Project Dependencies

  • Typesafe-Actions Version: 5.2.0
  • TypeScript Version: 3.6.3
  • tsconfig.json:
{
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist",
    "paths": {
      "@/*": ["src/*"]
    },
    "module": "es2015",
    "target": "es2015",
    "lib": ["es6", "dom"],
    "sourceMap": true,
    "allowJs": true,
    "jsx": "react",
    "moduleResolution": "node",
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "importHelpers": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": true
  },
  "exclude": [
    "node_modules",
    "build",
    "scripts",
    "acceptance-tests",
    "webpack",
    "jest",
    "src/setupTests.ts"
  ]
}
@piotrwitek
Copy link
Owner

piotrwitek commented Nov 27, 2019

Hi @cloudshadow
Report is invalid because it's missing info bug I guess rootAction.someActions.success is not a correct string literal type.

Please follow the bug report template and I will reopen the issue.

provide a full working code example below including actions, reducers and your custom types used in the example.

@cloudshadow
Copy link
Author

cloudshadow commented Nov 27, 2019

Hi Piotrwitek
i think rootAction.someActions.success is correct

@piotrwitek
Copy link
Owner

piotrwitek commented Nov 27, 2019

@cloudshadow
Ok I have found the reason, it's a reported bug in TypeScript: microsoft/TypeScript#29718

I would recommend to go there and ask in the issue when are they planning to fix it to show the interest coming from the community.

Related issue: #140

TODO:
I have to update the documentation to highlight the bug and link to the TypeScript issue

@piotrwitek piotrwitek reopened this Nov 27, 2019
@piotrwitek piotrwitek changed the title Object map style can not get the type of action and state Object map style cannot use getType to match action in the createReucer Nov 27, 2019
@piotrwitek piotrwitek changed the title Object map style cannot use getType to match action in the createReucer Object map style cannot use getType to match action in the createReducer Nov 27, 2019
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