Skip to content

Multi-type prop validation is not consistent #3879

@aphofstede

Description

@aphofstede

Vue.js version

2.0.1

Reproduction Link

https://jsfiddle.net/alexman/f7sb0rd3/9/

Steps to reproduce

Create a component with a prop of type [String, Boolean] and instantiate it with a boolean value or shorthand prop notation. (<my-component my-prop></my-component>)

What is Expected?

Booleans are accepted and passed to the validator as a boolean value.

What is actually happening?

You'll see that it will not validate booleans / shorthand prop notation.
Defining it reversed, [Boolean, String], does seem to work as expected except for not being able to pass false as a value.

Observations

I noticed validateProp() does the following "magic", which doesn't seem to take the option of an array of types into account?

  if (getType(prop.type) === 'Boolean') {
    if (absent && !hasOwn(prop, 'default')) {
      value = false
    } else if (value === '' || value === hyphenate(key)) {
      value = true
    }
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions