Say you have a function that returns the following:
const useHook0 = (props) => {
...
API call
...
return [varA, varB, varC] as [boolean, boolean, any]
}
And then you wish to use it in another function like so:
const [itemA, itemB, itemC]: [boolean, boolean, number] = useHook0(configA);
const [itemA1, itemB1, itemC1]: [boolean, boolean, string] = useHook0(configB);
Is there a way to apply types to the original array, say in the form of an interface, such that you only need to indicate what type the 3rd constant will be?
In other words, I feel that writing : [boolean, boolean, number] or : [boolean, boolean, string] is redundant and unnecessary, but I'm unable to find a more concise way of doing this.
EDIT:
The reason why it is being constructed in that manner is that function0 is a hook that is making API calls. So the data can be in many different forms.
The reason why I am not providing it in the form of an object is that if I have multiple API calls being made within one function, I need the ability to rename the constants.
EDIT 2:
The intent in avoiding an assertion each time is to make it such that when itemA.map(result => ...) is called 5 times, I don't need to write itemA.map((result: string) => ...) every single time. Just trying to follow DRY.
any? Or are the types actually limited? You could just make the type be[boolean, boolean, string | number]...