Alternative way of typing actions for dataPersistence when using NGRX 8
See original GitHub issueExpected Behavior
I can type action parameters on a less verbose way using ngrx 8 action creators creators.
Current Behavior
In order to be able to type my actions, so I can use their payload on the run/onError methods, I need to do ReturnType<typeof createCategoryDefinition>
where createCategoryDefinition
is
import { createAction, props } from '@ngrx/store';
export const createCategoryDefinition = createAction(
'[Category Definitions/API] create category definition',
props<{ creationData: CategoryDefinitionCreationData }>()
);
@Effect()
createCategoryDefinitionEffect$ = this.dataPersistence.fetch<ReturnType<typeof createCategoryDefinition>>(
createCategoryDefinition.type,
{
run: action => {
return this.categoryDefinitionService
.createCategoryDefinition(action.creationData)
.pipe(
map(categoryDefinition => createCategoryDefinitionSuccess({ categoryDefinition}))
);
},
onError: (action, error) => {
return createCategoryDefinitionFailure({ error });
},
}
);
Is there maybe some other way to leverage typescript to ease the typing of said actions?
Context
Latest version of NX. Version 8.x of NGRX.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Strong Typing the State and Actions in NgRx - This Dot Labs
When working with NgRx store, it is highly recommended to provide strong and explicit types for both the State and Actions. This becomes...
Read more >How do you dispatch multiple Actions from an Effect in Ngrx
You can use `switchMap for this - Dispatching Multiple Actions from NGRX Effects @Effect() save = this.update$.pipe( map(action ...
Read more >Dispatch Strongly Typed Action Objects to an ngrx Store in ...
Actions in an ngrx application are fundamentally very simple with a type property and usually a payload property. As a result, actions can...
Read more >NgRx – tips & tricks - Angular.love
However, very few people know that using this operator without the ... that when the same action is called for different objects the...
Read more >Managing State in Angular Applications using NgRx - Nx Blog
I use NgRx 8, entity, creator functions. I use NestJS to implement the ... In other words, the router should invoke the reducer,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I tested the new schematics, but I have to either add the
ReturnType<typeof actionCreator>
to the generic argument fordataPersistence.fetch
or add it to theid
,run
andonError
callbacks.any progress on this?