{"record":{"id":"ffb2b20b905e6126","repo":"dotnet/AspNetCore.Docs","slug":"ko-mapping-defaultoptions-include-should-be-an-a-ffb2b2","errorCode":null,"errorMessage":"ko.mapping.defaultOptions().include should be an array.","messagePattern":"ko\\.mapping\\.defaultOptions\\(\\)\\.include should be an array\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"aspnetcore/mvc/controllers/testing/samples/3.x/TestingControllersSample/src/TestingControllersSample/wwwroot/js/knockout.mapping.js","lineNumber":156,"sourceCode":"\t\tvar parsed = ko.utils.parseJson(jsonString);\n\t\targuments[0] = parsed;\n\t\treturn exports.fromJS.apply(this, arguments);\n\t};\n\n\texports.updateFromJS = function (viewModel) {\n\t\tthrow new Error(\"ko.mapping.updateFromJS, use ko.mapping.fromJS instead. Please note that the order of parameters is different!\");\n\t};\n\n\texports.updateFromJSON = function (viewModel) {\n\t\tthrow new Error(\"ko.mapping.updateFromJSON, use ko.mapping.fromJSON instead. Please note that the order of parameters is different!\");\n\t};\n\n\texports.toJS = function (rootObject, options) {\n\t\tif (!defaultOptions) exports.resetDefaultOptions();\n\n\t\tif (arguments.length == 0) throw new Error(\"When calling ko.mapping.toJS, pass the object you want to convert.\");\n\t\tif (exports.getType(defaultOptions.ignore) !== \"array\") throw new Error(\"ko.mapping.defaultOptions().ignore should be an array.\");\n\t\tif (exports.getType(defaultOptions.include) !== \"array\") throw new Error(\"ko.mapping.defaultOptions().include should be an array.\");\n\t\tif (exports.getType(defaultOptions.copy) !== \"array\") throw new Error(\"ko.mapping.defaultOptions().copy should be an array.\");\n\n\t\t// Merge in the options used in fromJS\n\t\toptions = fillOptions(options, rootObject[mappingProperty]);\n\n\t\t// We just unwrap everything at every level in the object graph\n\t\treturn exports.visitModel(rootObject, function (x) {\n\t\t\treturn ko.utils.unwrapObservable(x)\n\t\t}, options);\n\t};\n\n\texports.toJSON = function (rootObject, options) {\n\t\tvar plainJavaScriptObject = exports.toJS(rootObject, options);\n\t\treturn ko.utils.stringifyJson(plainJavaScriptObject);\n\t};\n\n\texports.defaultOptions = function () {\n\t\tif (arguments.length > 0) {","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/dotnet/AspNetCore.Docs/blob/c67a80103a1a74db20784debd919c7fdda96c510/aspnetcore/mvc/controllers/testing/samples/3.x/TestingControllersSample/src/TestingControllersSample/wwwroot/js/knockout.mapping.js#L138-L174","documentation":"knockout.mapping.js validates `defaultOptions().include` is an array. include lists properties that mapping should process even when they are not normally mapped (e.g. computed observables); a non-array breaks the merge logic.","triggerScenarios":"Assigning `defaultOptions().include` to a non-array (string, number, object) and then invoking any mapping operation that consults defaultOptions.","commonSituations":"Writing `include: \"fullName\"` instead of an array; bad merge of partial option objects; stale config from an older API version that accepted other shapes.","solutions":["Set include as an array of property names: `ko.mapping.defaults.include = [\"fullName\"];`.","Call `ko.mapping.resetDefaultOptions()` to clear the bad state.","Centralize option setup in one bootstrap module so include/ignore/copy stay arrays."],"exampleFix":"// before\nko.mapping.defaults.include = \"computedField\";\n\n// after\nko.mapping.defaults.include = [\"computedField\"];","handlingStrategy":"validation","validationCode":"function setInclude(props) {\n  if (!Array.isArray(props)) throw new TypeError('include must be an array');\n  ko.mapping.defaults.include = props;\n}","typeGuard":"function isValidOptionArray(v) {\n  return Array.isArray(v) && v.every(x => typeof x === 'string');\n}","tryCatchPattern":"// Validate options at app start rather than catching per call:\n['ignore','include','copy'].forEach(k => {\n  if (!Array.isArray(ko.mapping.defaults[k])) ko.mapping.resetDefaultOptions();\n});","preventionTips":["Keep option setup centralized.","Lint that all three option arrays are array literals.","Reset defaults before applying custom config in tests."],"tags":["knockout","configuration","type-error","mapping"],"backgroundTag":null,"analyzedSha":"c67a80103a1a74db20784debd919c7fdda96c510","analyzedAt":"2026-08-13T17:46:11.763Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}