Home / Function/ assertProp() — vue Function Reference

assertProp() — vue Function Reference

Architecture documentation for the assertProp() function in props.ts from the vue codebase.

Entity Profile

Dependency Diagram

graph TD
  87f7db47_5b28_fa14_0778_0d908fd6f104["assertProp()"]
  d99d7982_2691_1c11_3bae_459f2d25122d["validateProp()"]
  d99d7982_2691_1c11_3bae_459f2d25122d -->|calls| 87f7db47_5b28_fa14_0778_0d908fd6f104
  e3484a9f_f8a5_4082_0208_641d58b965c3["warn()"]
  87f7db47_5b28_fa14_0778_0d908fd6f104 -->|calls| e3484a9f_f8a5_4082_0208_641d58b965c3
  a932425d_6366_3fdb_331a_b75977c60593["assertType()"]
  87f7db47_5b28_fa14_0778_0d908fd6f104 -->|calls| a932425d_6366_3fdb_331a_b75977c60593
  d3d22bbe_e895_cdde_5564_f0b46800e133["getInvalidTypeMessage()"]
  87f7db47_5b28_fa14_0778_0d908fd6f104 -->|calls| d3d22bbe_e895_cdde_5564_f0b46800e133
  style 87f7db47_5b28_fa14_0778_0d908fd6f104 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/core/util/props.ts lines 105–147

function assertProp(
  prop: PropOptions,
  name: string,
  value: any,
  vm?: Component,
  absent?: boolean
) {
  if (prop.required && absent) {
    warn('Missing required prop: "' + name + '"', vm)
    return
  }
  if (value == null && !prop.required) {
    return
  }
  let type = prop.type
  let valid = !type || (type as any) === true
  const expectedTypes: string[] = []
  if (type) {
    if (!isArray(type)) {
      type = [type]
    }
    for (let i = 0; i < type.length && !valid; i++) {
      const assertedType = assertType(value, type[i], vm)
      expectedTypes.push(assertedType.expectedType || '')
      valid = assertedType.valid
    }
  }

  const haveExpectedTypes = expectedTypes.some(t => t)
  if (!valid && haveExpectedTypes) {
    warn(getInvalidTypeMessage(name, value, expectedTypes), vm)
    return
  }
  const validator = prop.validator
  if (validator) {
    if (!validator(value)) {
      warn(
        'Invalid prop: custom validator check failed for prop "' + name + '".',
        vm
      )
    }
  }
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does assertProp() do?
assertProp() is a function in the vue codebase.
What does assertProp() call?
assertProp() calls 3 function(s): assertType, getInvalidTypeMessage, warn.
What calls assertProp()?
assertProp() is called by 1 function(s): validateProp.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free