solidjs/solid · error · Error

Unexpected type ${typeof unwrappedStore} received when initi

Error message

Unexpected type ${typeof unwrappedStore} received when initializing 'createMutable'. Expected an object.

What it means

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.

Source

Thrown at packages/solid/store/src/mutable.ts:146

        });
      }
      if (desc[prop].set) {
        const og = desc[prop].set!,
          set = (v: T[keyof T]) => batch(() => og.call(p, v));
        Object.defineProperty(value, prop, {
          set,
          configurable: true
        });
      }
    }
  }
  return p;
}

export function createMutable<T extends StoreNode>(state: T, options?: { name?: string }): T {
  const unwrappedStore = unwrap(state || {});
  if (IS_DEV && typeof unwrappedStore !== "object" && typeof unwrappedStore !== "function")
    throw new Error(
      `Unexpected type ${typeof unwrappedStore} received when initializing 'createMutable'. Expected an object.`
    );

  const wrappedStore = wrap(unwrappedStore);
  if (IS_DEV) DEV!.registerGraph({ value: unwrappedStore, name: options && options.name });
  return wrappedStore;
}

export function modifyMutable<T>(state: T, modifier: (state: T) => T) {
  batch(() => modifier(unwrap(state)));
}

View on GitHub (pinned to f47845f9cc)

Solutions

  1. Use createSignal for primitive state
  2. Wrap the primitive in an object: createMutable({ value: 'hello' })
  3. If state may be object-or-primitive, branch: typeof v === 'object' ? createMutable(v) : createSignal(v)

Example fix

// before
const name = createMutable('Alice'); // throws in dev

// after
const [name, setName] = createSignal('Alice');
// or
const nameStore = createMutable({ value: 'Alice' });
Defensive patterns

Strategy: type-guard

Validate before calling

const isStoreNodeInit = (v: unknown): v is object | Function =>
  typeof v === 'object' || typeof v === 'function';
if (!isStoreNodeInit(state)) throw new Error('createMutable needs an object; use createSignal for primitives');

Type guard

const isMutableState = (v: unknown): v is Record<string, unknown> =>
  !!v && (typeof v === 'object' || typeof v === 'function');

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of solidjs/solid@f47845f9cc (2026-08-27). Data as JSON: /api/errors/b10e77e5f2906f17. Report an issue: GitHub.