Peter
Peter
SSolidJS
Created by Peter on 3/23/2024 in #support
How to create a wrapper for SolidJS's setStore in TypeScript?
I have a SolidJS store defined:
const [store, setStore] = createStore<SomeComplexType>();
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);
};
// @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?
7 replies