{"record":{"id":"164f4ee41edfac85","repo":"reduxjs/redux","slug":"expected-the-observer-to-be-an-object-instead-re","errorCode":null,"errorMessage":"Expected the observer to be an object. Instead, received: '${kindOf(observer)}'","messagePattern":"Expected the observer to be an object\\. Instead, received: '(.+?)'","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/createStore.ts","lineNumber":357,"sourceCode":"   * Interoperability point for observable/reactive libraries.\n   * @returns A minimal observable of state changes.\n   * For more information, see the observable proposal:\n   * https://github.com/tc39/proposal-observable\n   */\n  function observable() {\n    const outerSubscribe = subscribe\n    return {\n      /**\n       * The minimal observable subscription method.\n       * @param observer Any object that can be used as an observer.\n       * The observer object should have a `next` method.\n       * @returns An object with an `unsubscribe` method that can\n       * be used to unsubscribe the observable from the store, and prevent further\n       * emission of values from the observable.\n       */\n      subscribe(observer: unknown) {\n        if (typeof observer !== 'object' || observer === null) {\n          throw new TypeError(\n            `Expected the observer to be an object. Instead, received: '${kindOf(\n              observer\n            )}'`\n          )\n        }\n\n        function observeState() {\n          const observerAsObserver = observer as Observer<S>\n          if (observerAsObserver.next) {\n            observerAsObserver.next(getState())\n          }\n        }\n\n        observeState()\n        const unsubscribe = outerSubscribe(observeState)\n        return { unsubscribe }\n      },\n","sourceCodeStart":339,"sourceCodeEnd":375,"githubUrl":"https://github.com/reduxjs/redux/blob/3084fc33bb23ab4cab4796172eafe342da4e73d9/src/createStore.ts#L339-L375","documentation":"store[Symbol.observable]().subscribe(observer) accepts an observer object (with optional next/error/complete methods). The interop checks typeof observer === 'object' && observer !== null and throws a TypeError otherwise. This is distinct from store.subscribe(listener) which takes a function; passing a function here is a misuse of the observable API.","triggerScenarios":"store[Symbol.observable]().subscribe(() => render()) — passing a function to the observable subscribe; subscribe(null) or subscribe('cb'); using a subscriber library that hands a callback instead of an observer; RxJS interop where the observer unwrapped to a function.","commonSituations":"Confusing store.subscribe(fn) with observable.subscribe(observer); adapter code that bridges Redux to RxJS incorrectly; passing an arrow function where an { next } object is expected; migrating from a custom subscribe-API that accepted functions.","solutions":["Pass an observer object: `store[Symbol.observable]().subscribe({ next: state => render() })`.","If you just want a plain callback, use store.subscribe(listener) directly (no Symbol.observable).","When bridging to RxJS, ensure the observer is `{ next, error?, complete? }`, not a bare function."],"exampleFix":"// before\nstore[Symbol.observable]().subscribe(state => render())   // function, not object -> TypeError\n\n// after\nstore[Symbol.observable]().subscribe({ next: state => render() })\n// or, for a plain callback, skip the observable interop:\nstore.subscribe(() => render())","handlingStrategy":"type-guard","validationCode":"if (observer === null || typeof observer !== 'object') {\n  throw new TypeError(`observer must be an object, got ${observer === null ? 'null' : typeof observer}`)\n}\nstore[Symbol.observable]().subscribe(observer)","typeGuard":"const isObserver = (x): x is { next?: (s:any)=>void; error?: (e:any)=>void; complete?: ()=>void } =>\n  x !== null && typeof x === 'object'","tryCatchPattern":null,"preventionTips":["Pass an observer object ({ next }) to the observable subscribe, not a bare function.","For plain callbacks, use store.subscribe(listener) instead of the observable interop.","When bridging to RxJS, ensure the observer is a proper { next, error?, complete? } object."],"tags":["redux","createstore","observable","observer","interop","type-validation"],"backgroundTag":null,"analyzedSha":"3084fc33bb23ab4cab4796172eafe342da4e73d9","analyzedAt":"2026-08-12T13:21:41.727Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}