{"record":{"id":"c827e8b3eb6be565","repo":"Meituan-Dianping/mpvue","slug":"props-must-be-strings-when-using-array-syntax-c827e8","errorCode":null,"errorMessage":"props must be strings when using array syntax.","messagePattern":"props must be strings when using array syntax\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/platforms/mp/runtime/lifecycle.js","lineNumber":115,"sourceCode":"//       // 这个值必须匹配下列字符串中的一个\n//       return ['success', 'warning', 'danger'].indexOf(value) !== -1\n//     }\n//   }\n// }\n\n// core/util/options\nfunction normalizeProps (props, res, vm) {\n  if (!props) return\n  let i, val, name\n  if (Array.isArray(props)) {\n    i = props.length\n    while (i--) {\n      val = props[i]\n      if (typeof val === 'string') {\n        name = camelize(val)\n        res[name] = { type: null }\n      } else if (process.env.NODE_ENV !== 'production') {\n        warn('props must be strings when using array syntax.')\n      }\n    }\n  } else if (isPlainObject(props)) {\n    for (const key in props) {\n      val = props[key]\n      name = camelize(key)\n      res[name] = isPlainObject(val)\n        ? val\n        : { type: val }\n    }\n  }\n\n  // fix vueProps to properties\n  for (const key in res) {\n    if (res.hasOwnProperty(key)) {\n      const item = res[key]\n      if (item.default) {\n        item.value = item.default","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/Meituan-Dianping/mpvue/blob/6c5d78ee04f58c6d782c456dfcf0fe63c0b7f89b/src/platforms/mp/runtime/lifecycle.js#L97-L133","documentation":"A component declared props with array syntax but included a non-string entry (e.g. an object or number). Array syntax requires every element to be a prop name string; object syntax is needed for type declarations. Vue warns and skips the invalid entry.","triggerScenarios":"Dev-mode normalization of props: props: ['name', { type: String }] or props: [123] passed to normalizeProps (called by normalizeProperties) during component init/extension.","commonSituations":"Mixing array and object prop declarations by mistake; dynamically building a props array and accidentally pushing prop definition objects; typos in component factory code.","solutions":["Make every array element a string: props: ['a', 'b'].","If you need types, switch to object syntax: props: { a: String }.","Log/inspect the props array (console.log) to find the non-string element."],"exampleFix":"// before\nprops: ['title', { type: Number, default: 0 }]\n// after\nprops: { title: String, count: { type: Number, default: 0 } }","handlingStrategy":"validation","validationCode":"function assertValidProps (props) {\n  if (Array.isArray(props)) {\n    props.forEach((p, i) => {\n      if (typeof p !== 'string') throw new Error('props[' + i + '] must be a string when using array syntax')\n    })\n  }\n}\nassertValidProps(['title', 'count'])","typeGuard":"const isStringPropsArray = (props) =>\n  Array.isArray(props) && props.every(p => typeof p === 'string');","tryCatchPattern":null,"preventionTips":["Pick one syntax: strings array OR object with type definitions","Never mix definition objects into a props array","Type-check component options with a linter/TS before runtime","Unit-test mounting each component to surface dev warnings"],"tags":["vue","props","component-options"],"backgroundTag":"vue-invalid-props-declaration","analyzedSha":"6c5d78ee04f58c6d782c456dfcf0fe63c0b7f89b","analyzedAt":"2026-09-02T05:17:40.946Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}