{"record":{"id":"e831b5384e834995","repo":"krisk/Fuse","slug":"incorrect-index-type","errorCode":null,"errorMessage":"Incorrect 'index' type","messagePattern":"Incorrect 'index' type","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/core/index.ts","lineNumber":112,"sourceCode":"\n  _getSearcher(query: string): Searcher {\n    if (this._lastQuery === query) {\n      return this._lastSearcher!\n    }\n    const opts = this._invertedIndex\n      ? { ...this.options, _invertedIndex: this._invertedIndex }\n      : this.options\n    const searcher = createSearcher(query, opts)\n    this._lastQuery = query\n    this._lastSearcher = searcher\n    return searcher\n  }\n\n  setCollection(docs: ReadonlyArray<T>, index?: FuseIndex<T>): void {\n    this._docs = docs as T[]\n\n    if (index && !(index instanceof FuseIndex)) {\n      throw new Error(ErrorMsg.INCORRECT_INDEX_TYPE)\n    }\n\n    this._myIndex =\n      index ||\n      createIndex(this.options.keys, this._docs, {\n        getFn: this.options.getFn,\n        fieldNormWeight: this.options.fieldNormWeight\n      })\n\n    if (this.options.useTokenSearch) {\n      const analyzer = createAnalyzer({\n        isCaseSensitive: this.options.isCaseSensitive,\n        ignoreDiacritics: this.options.ignoreDiacritics,\n        tokenize: this.options.tokenize\n      })\n      this._invertedIndex = buildInvertedIndex(\n        this._myIndex.records,\n        this._myIndex.keys.length,","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/krisk/Fuse/blob/edf2fb608eca0461508d1d71317e6e58309ffada/src/core/index.ts#L94-L130","documentation":"Fuse.setCollection(docs, index) accepts an optional pre-built index as its second argument, but it must be a genuine FuseIndex instance. Passing anything else (plain object, array, index from a different Fuse copy) throws this error so a malformed index is never silently used. It exists to catch stale or hand-rolled index objects.","triggerScenarios":"fuse.setCollection(docs, someObject) where someObject is not created by Fuse.createIndex(...) — e.g. a serialized/cached index from a different Fuse version, a plain array, or a duplicate-package instanceof mismatch.","commonSituations":"Caching indexes built by a different installed copy of fuse.js (duplicate dependency causing instanceof to fail); hand-rolling an index object; upgrading Fuse while reusing old serialized indexes.","solutions":["Create the index with Fuse.createIndex(keys, docs) from the SAME installed Fuse module and pass that to setCollection.","Omit the second argument and let Fuse build the index itself.","Dedupe fuse.js in node_modules if instanceof mismatches come from multiple package copies."],"exampleFix":"// before\nconst index = buildMyOwnIndex(keys, docs) // plain object\nfuse.setCollection(newDocs, index)\n// after\nimport Fuse from 'fuse.js'\nconst index = Fuse.createIndex(['title'], newDocs)\nfuse.setCollection(newDocs, index)","handlingStrategy":"type-guard","validationCode":"import Fuse, { FuseIndex } from 'fuse.js'\nif (index !== undefined && !(index instanceof FuseIndex)) {\n  throw new TypeError('setCollection requires a FuseIndex from Fuse.createIndex')\n}\nfuse.setCollection(docs, index)","typeGuard":"const isFuseIndex = (v) => v instanceof FuseIndex","tryCatchPattern":"try {\n  fuse.setCollection(docs, index)\n} catch (e) {\n  if (e.message === \"Incorrect 'index' type\") {\n    fuse.setCollection(docs) // let Fuse rebuild the index\n  } else {\n    throw e\n  }\n}","preventionTips":["Always build indexes with Fuse.createIndex from the same module instance.","Dedupe fuse.js in node_modules to avoid instanceof mismatches.","Omit the index argument unless you hold a valid pre-built one."],"tags":["argument-validation","type-error","index"],"backgroundTag":"invalid-argument-value","analyzedSha":"edf2fb608eca0461508d1d71317e6e58309ffada","analyzedAt":"2026-09-02T02:46:54.623Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}