Is it possible to achieve the following in Typescript:
I want the type of state.initial to be deduced as a tuple based on the input to takeConfig. It would also be nice to deduce the return type of initialState based on the type of the state property of the component function's props argument (Although the latter, I believe, is not possible without changing this API).
type State1 = { a: string };
type State2 = { b: string };
function Component1(props: { state: State1 }) {}
function Component2(props: { state: State2 }) {}
const state = takeConfig([
{
component: Component1,
initialState: () => ({
a: "a"
}) // return type here is deduced to be State1
},
{
component: Component2,
initialState: () => ({
b: "b"
}) // return type here is deduced to be State2
},
]);
// type here is deduced to be [State1, State2]
state.initial
Thanks!