type SomeType = { key1: string; key2: number; key3: boolean; } export type MySpecialObject = { theThingIWantToUpdate: SomeType; // with other keys and stuff } export type MyContextStateType = { myValue: SomeOtherType; myArray: MySpecialObject[]; } export type MyContextType = { myContext: Store; pushObjectToMyArray: (myObject: MySpecialObject) => void; setObjectAtIndex: (myObject: MySpecialObject, index: number) => void; setAttributeAtIndex: (key: keyof MySpecialObject, value: any, index: number) => void; etc; } export function MyContextProvider() { const [myValue] = createResource(myValueId, myValueFetcher); let myContext: MyContextType = undefined; const [isReady, setIsReady] = createSignal(false); createMemo(async () =>{ if (myValue() && !myContext) { myContext = await initMyContext(myValue); setIsReady(true); } }); return ( {props.children} ); } export const initMyContext = (myValue: SomeOtherType) => { const [myContext, setMyContext] = createStore({ myValue: myValue, myArray: [] }); // do stuff to initialize return { myContext: myContext, pushObjectToMyArray: (myObject: MySpecialObject) => { setMyContext('myArray', (arr: MySpecialObject[]) => [ ...arr, { ...myObject } ]); }, setObjectAtIndex: (myObject: MySpecialObject, index: number) => { setMyContext('myArray', index, { ...myObject }); }, setAttributeAtIndex: (key: keyof MySpecialObject, value: any, index: number) => { setMyContext( 'myArray', index, 'theThingIWantToUpdate', key, value ); } } }