while learning in react 16.8 with typescript code base, I came through many diffrent type definition pattern is been followed.
so for the sake of consistency,
which is the right way (recommended or valid) to set a type definition of a es6 arrow method especially when object destructuring comes into picture
so my first question is what is the right way to define (or set, what it called) type of a function
- write just after the function name , before
=
const method: MethodType = (state:AlphaState , action: AlphaAction) => {
return data;
}
- after the parameter listing , just before
=>
const method = (state:AlphaState , action: AlphaAction): MethodType => ({
})
now second part of my question is if we use object destructuring in parameter then it become more complex .
Where to write parameters type and whether it can be conflicts with parameter typing and function typing signature?
So here is in case of object
- write against each property of parameter object, just before each
,
const appMethod: MethodType = ({state:AppState , action: AppAction}) => ({
}
- after the parameter list, a separate type list with same type order after destructuring done, i.e. after first closing
}
const appMethod: MethodType = ({state , action}:{AppState, AppAction}) => {}
Also welcome any other or recommended style to handle this.