SolidJSS
SolidJSโ€ข2y agoโ€ข
6 replies
Peter

How to create a wrapper for SolidJS's setStore in TypeScript?

I have a SolidJS store defined:
const [store, setStore] = createStore<SomeComplexType>();

I need to run some code before every execution of setStore, so I would like to wrap it with my own function. Is there a way to do that, that preserves all types and all overloads?

So far, the best solution I've (heard)[https://stackoverflow.com/questions/78209469/how-to-create-a-wrapper-for-solidjss-setstore-in-typescript?noredirect=1#comment137881170_78209469] is:
// @ts-expect-error
const setStoreWithEffect: SetStoreFunction<Foo> = (...params: [any]) => {
    console.log("setStore invoked with parameters:", params);
    return setStore(...params);
};

But the error suppression makes it ugly. Is there any clean way to do this?
Stack Overflow
I have a SolidJS store defined:
const [store, setStore] = createStore<SomeComplexType>();

I need to run some code before every execution of setStore, so I would like to wrap it with my own
How to create a wrapper for SolidJS's setStore in TypeScript?
Was this page helpful?