Skip to content

Null is not treated as Object in component prop check #1961

@fnlctrl

Description

@fnlctrl

I have a component that let's user select an object from an array.

<comp :selected.sync="selectedObject">
// parent data
data: {
    selectedObject: null
}
// comp prop
props: {
    selected: {twoWay: true, type: Object}
}

and in parent template I have something like

<div v-if="selectedObject"> blah blah blah </div>
<div v-else> please select an object </div>

which displays different content based on whether an object is selected.

and I get

[Vue warn]: Invalid prop: type check failed for selected="selectedObject". Expected Object, got Null.

I know i can just remove the "type: Object" check and suppress the warning,
but wouldn't it be better if component props checks treat null as an object?

Because javascript does that (typeof null === 'object'),
and setting null as an initial value (to my knowledge) doesn't affect mutation observation.

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