Open tripolskypetr opened 2 years ago
Here you are: Link to playgroundββ
declare namespace JSX {
export type Element = any;
}
interface IOptionalTupleProps<A, B, C> {
fetchState: () => Promise<[A?, B?, C?]> | [A?, B?, C?];
children: (...data: [A?, B?, C?]) => JSX.Element;
};
const OptionalTuple = async <A, B, C>({
fetchState,
children,
}: IOptionalTupleProps<A, B, C>) => {
const data = await Promise.all(await fetchState());
return children(...data);
}
const App = () => {
const fetchState = () => Promise.all([
Promise.resolve(1),
Promise.resolve(2),
Promise.resolve(3),
]);
return OptionalTuple({
fetchState,
children: console.log,
});
}
App();
β Suggestion
Make support for optional generic arguments in tuple
π Motivating Example
I have the next JS code. It will type
1, 2, 3
into Chrome Dev Tools console outputI want to make It strictly typed to enable IntelliSense in VSCode. I tried, so I attach my last attempt below
But for now I am getting the following error. It looks like
readonly [Promise<number>]
can't be casted to[Promise<number>, void, void]
π» Use Cases
Optional tuple arguments can be used in React higher-order-components to enable powered type checking in functional programming
π Search Terms
cannot be assigned to the mutable type '[void, void, void]'
type '[Promise<number>]' cannot be assigned to '[Promise<number>, void, void]'
readonly cannot be assigned
Argument of type '[]' is not assignable to parameter of type
optional generic rest parameters union not callable
β Viability Checklist
My suggestion meets these guidelines: