{"record":{"id":"b10e77e5f2906f17","repo":"solidjs/solid","slug":"unexpected-type-typeof-unwrappedstore-received","errorCode":null,"errorMessage":"Unexpected type ${typeof unwrappedStore} received when initializing 'createMutable'. Expected an object.","messagePattern":"Unexpected type (.+?) received when initializing 'createMutable'\\. Expected an object\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/solid/store/src/mutable.ts","lineNumber":146,"sourceCode":"        });\n      }\n      if (desc[prop].set) {\n        const og = desc[prop].set!,\n          set = (v: T[keyof T]) => batch(() => og.call(p, v));\n        Object.defineProperty(value, prop, {\n          set,\n          configurable: true\n        });\n      }\n    }\n  }\n  return p;\n}\n\nexport function createMutable<T extends StoreNode>(state: T, options?: { name?: string }): T {\n  const unwrappedStore = unwrap(state || {});\n  if (IS_DEV && typeof unwrappedStore !== \"object\" && typeof unwrappedStore !== \"function\")\n    throw new Error(\n      `Unexpected type ${typeof unwrappedStore} received when initializing 'createMutable'. Expected an object.`\n    );\n\n  const wrappedStore = wrap(unwrappedStore);\n  if (IS_DEV) DEV!.registerGraph({ value: unwrappedStore, name: options && options.name });\n  return wrappedStore;\n}\n\nexport function modifyMutable<T>(state: T, modifier: (state: T) => T) {\n  batch(() => modifier(unwrap(state)));\n}\n","sourceCodeStart":128,"sourceCodeEnd":158,"githubUrl":"https://github.com/solidjs/solid/blob/f47845f9cc16ecbb316aa6560c7161f45af9a3d8/packages/solid/store/src/mutable.ts#L128-L158","documentation":"createMutable requires its initial state to unwrap to an object or function (a store node). Passing a primitive (string, number, boolean) fails the dev-only check and throws. createMutable wraps an object in a reactive proxy, so a primitive has nothing to wrap; use createSignal for primitives.","triggerScenarios":"createMutable('hello'), createMutable(42), createMutable(null-then-string via || {}), or passing JSON.parse output that is a bare primitive; also passing a value typed as T extends StoreNode that is actually primitive at runtime.","commonSituations":"Porting state where a value starts as a string; generic/wrapped APIs forwarding arbitrary user state into createMutable; defaults like state || {} masking until a primitive arrives later.","solutions":["Use createSignal for primitive state","Wrap the primitive in an object: createMutable({ value: 'hello' })","If state may be object-or-primitive, branch: typeof v === 'object' ? createMutable(v) : createSignal(v)"],"exampleFix":"// before\nconst name = createMutable('Alice'); // throws in dev\n\n// after\nconst [name, setName] = createSignal('Alice');\n// or\nconst nameStore = createMutable({ value: 'Alice' });","handlingStrategy":"type-guard","validationCode":"const isStoreNodeInit = (v: unknown): v is object | Function =>\n  typeof v === 'object' || typeof v === 'function';\nif (!isStoreNodeInit(state)) throw new Error('createMutable needs an object; use createSignal for primitives');","typeGuard":"const isMutableState = (v: unknown): v is Record<string, unknown> =>\n  !!v && (typeof v === 'object' || typeof v === 'function');","tryCatchPattern":null,"preventionTips":["Use createSignal for primitive state","Box primitives in objects when they must live in a store","Validate API payloads' root type before creating mutable stores"],"tags":["solid","store","createmutable","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"}