Review Show wrapper for multiple signals in TypeScript

Hello! I need your help reviewing a solution I created. I initially encountered a problem when using Solid + TypeScript to conditionally render multiple signals. I want to pass several signals to a Show component that may contain undefined values and, within the children function, access all the passed signals separately. https://playground.solidjs.com/anonymous/cd0b9dce-db4a-400f-88b9-8a23ea88e05e Here is an example of the Show wrapper I created. It works as expected, but I’d appreciate your help identifying any potential pitfalls or edge cases. Thanks for your help!
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
5 Replies
zulu
zulu2w ago
No description
zulu
zulu2w ago
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
zulu
zulu2w ago
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
Madaxen86
Madaxen862w ago
I'll copy this here in case anyone searche for it. Type narrow for multiple signals
function all<T extends unknown[]>(accessors: {
[K in keyof T]: Accessor<T[K] | undefined>;
}): { [K in keyof T]: Accessor<T[K]> } | undefined {
if (accessors.every((accessor) => accessor() !== undefined)) {
return accessors as { [K in keyof T]: Accessor<T[K]> };
}
return undefined;
}
function all<T extends unknown[]>(accessors: {
[K in keyof T]: Accessor<T[K] | undefined>;
}): { [K in keyof T]: Accessor<T[K]> } | undefined {
if (accessors.every((accessor) => accessor() !== undefined)) {
return accessors as { [K in keyof T]: Accessor<T[K]> };
}
return undefined;
}
Victoria
VictoriaOP2w ago
Both options look really good 🚀 Thank you!

Did you find this page helpful?