{"record":{"id":"ec29fff3fd374b49","repo":"solidjs/solid","slug":"unexpected-type-typeof-unwrappedstore-received-ec29ff","errorCode":null,"errorMessage":"Unexpected type ${typeof unwrappedStore} received when initializing 'createStore'. Expected an object.","messagePattern":"Unexpected type (.+?) received when initializing 'createStore'\\. Expected an object\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/solid/store/src/store.ts","lineNumber":541,"sourceCode":"  ): void;\n}\n\nexport type StoreReturn<T> = [get: Store<T>, set: SetStoreFunction<T>];\n\n/**\n * Creates a reactive store that can be read through a proxy object and written with a setter function\n *\n * @description https://docs.solidjs.com/reference/store-utilities/create-store\n */\nexport function createStore<T extends object = {}>(\n  ...[store, options]: {} extends T\n    ? [store?: T | Store<T>, options?: { name?: string }]\n    : [store: T | Store<T>, options?: { name?: string }]\n): StoreReturn<T> {\n  const unwrappedStore = unwrap((store || {}) as T);\n  const isArray = Array.isArray(unwrappedStore);\n  if (IS_DEV && typeof unwrappedStore !== \"object\" && typeof unwrappedStore !== \"function\")\n    throw new Error(\n      `Unexpected type ${typeof unwrappedStore} received when initializing 'createStore'. Expected an object.`\n    );\n  const wrappedStore = wrap(unwrappedStore);\n  if (IS_DEV) DEV!.registerGraph({ value: unwrappedStore, name: options && options.name });\n  function setStore(...args: any[]): void {\n    batch(() => {\n      isArray && args.length === 1\n        ? updateArray(unwrappedStore, args[0])\n        : updatePath(unwrappedStore, args);\n    });\n  }\n\n  return [wrappedStore, setStore];\n}\n","sourceCodeStart":523,"sourceCodeEnd":556,"githubUrl":"https://github.com/solidjs/solid/blob/f47845f9cc16ecbb316aa6560c7161f45af9a3d8/packages/solid/store/src/store.ts#L523-L556","documentation":"createStore requires initial state that unwraps to an object or function (including arrays). Passing a primitive throws this dev-only error because the store proxy needs a node to wrap; the message includes the actual typeof received to pinpoint the mismatch. For primitive reactive state, createSignal is the intended API.","triggerScenarios":"createStore('text'), createStore(0), createStore(true); passing unwrapped JSON like JSON.parse('\"hi\"'); spreading props or forwarding a field that is sometimes a primitive; defaulting with (store || {}) failing when store is a non-null primitive.","commonSituations":"Migrating useState/useState-like primitive state to stores during React ports; REST payloads whose root can be a scalar; type errors where Store<T> vs T confusion lets a primitive through.","solutions":["Switch primitive state to createSignal: const [v, setV] = createSignal(0)","Box the value in the store: createStore({ value: 0 })","Validate/normalize initial data before createStore: assert typeof data === 'object'"],"exampleFix":"// before\nconst [count, setCount] = createStore(0); // throws: typeof 'number'\n\n// after\nconst [count, setCount] = createSignal(0);\n// or\nconst [state, setState] = createStore({ count: 0 });","handlingStrategy":"type-guard","validationCode":"const isStoreState = (v: unknown): v is object | Function =>\n  typeof v === 'object' || typeof v === 'function';\nif (!isStoreState(initial)) throw new TypeError('createStore requires object/array initial state');\nconst [state, setState] = createStore(initial);","typeGuard":"const isStoreState = (v: unknown): v is Record<PropertyKey, unknown> | unknown[] =>\n  !!v && typeof v === 'object';","tryCatchPattern":null,"preventionTips":["Reserve createStore for objects/arrays; use createSignal for scalars","Assert typeof on data from APIs/parsers before storing","Type store initializers so primitives fail at compile time"],"tags":["solid","store","createstore","validation","dev-only"],"backgroundTag":"invalid-initial-state-type","analyzedSha":"f47845f9cc16ecbb316aa6560c7161f45af9a3d8","analyzedAt":"2026-08-27T05:39:24.283Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}