typesafe-actions
typesafe-actions copied to clipboard
Object map style cannot use getType to match action in the createReducer
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"
]
}
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.
Hi Piotrwitek
i think rootAction.someActions.success is correct

@cloudshadow Ok I have found the reason, it's a reported bug in TypeScript: https://github.com/microsoft/TypeScript/issues/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