Skip to content

Invalid properties when passing empty string to a component #1107

Closed
@benjaminreid

Description

@benjaminreid

Hello,

I have a simple component with a property of foo which defaults to empty string:

Vue.component('my-component', {
    template: '<pre>{{ $data | json }}</pre>',
    props: {
        foo: {
            type: String,
            default: ''
        }
    }
});

When using this component like so:

<my-component></my-component>

The result is as expected:

{
  "foo": ""
}

But when passing an empty string as a property value (I know this could be worked around, but it's a scenario that I've run into) like so:

<my-component foo=""></my-component>

The result is as follows with this error [Vue warn]: Invalid prop: type check failed for foo="". Expected String, got Number..

{}

I'd expect the property to still be an empty string. Is this a bug, or expected behaviour?

Fiddle for example: http://jsfiddle.net/6szLn2fm/

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