I wanted to ask that if we can give any default value in the props<>() just like we give a default value in function arguments
export const set = createAction(
'[Counter] Set',
props<{ value: number }>()
);
Here I want to give a default number to "value" property in props<{ value: number }>().
Is there any way of doing so?
I tried adding the number similar to what we do in function arguments:
export const set = createAction(
'[Counter] Set',
props<{ value = 0 }>()
);
But it resulted in error!:
Operator '<' cannot be applied to types '<P extends SafeProps, SafeProps = NotAllowedInPropsCheck<P>>() => ActionCreatorProps<P>' and '{ value: number; }'
props<{ value: number }>()it's generics, not an embedded DSL.You get that error because
{ value = 0 }is not a valid type.{ value: 0 }is, but it means thatvalueis always0.If you want to signify that there's a default value, use
props<{ value?: number }>()orprops<{ value?: number|0 }>().Then in your reducer you can have something like: