Skip to content

Inconsistency in the validation of defaults between withDefaults and defineModel #14966

Description

@whysopaul

Vue version

3.5.38

Link to minimal reproduction

https://play.vuejs.org/#eNp9UttOwzAM/RUrLwypagUDCY0yxO0BJC4C3tYJlc7bMtIkStJtUrV/x0nVMQbbm+1zbJ8cp2ZXWsfzClmPpbYwXDuw6CrdzyQvtTIOblSpYWxUCQdx4hNPPzjPZJo0DUSlxGGpRe6QMoA0NCUUp8kGwCLmbKHkmE/imVWSltaenrGC+FygedaOK2kz1oOAeCwXQi0eQs2ZCqO2Xkyx+PqnPrNLX8vYi0GLZo4ZW2MuNxN0DXz39oRLitdgqUaVIPYe8BWtEpXX2NCuKzki2Ru8oPY+WMfl5N3eLR1K2z7KC/XMVeBnjKz0Vu16+o/cbnwS+jK5IhfbM2xfDUQuJxfUR2PIb7LaOtBGaQsXsOBueovjvBLOdkY45hJfPJSGdZzuZC97IKvyE81gSIv6ncOo0RLAHgyOIjiOoOvBQ/oB7QbyBgVtaIY++ixt5/Q7ta/7rTRgCKFx39cZ8XkIfoUAdd2ogBV5ENBkN7MR9JfZRtu/8mOOxt+I/OzGp3H3jK2+AX9gBOE=

Steps to reproduce

Define a model with non-factory object/array defaults:

const model = defineModel<number[]>({ default: [] });

What is expected?

A ts(2322) error, consistent with how withDefaults handles the same case:

const props = withDefaults(defineProps<{
  items?: number[]
}>(), {
  items: [],  // ts(2322): Type 'never[]' is not assignable to type 'InferDefault<...>'
});

What is actually happening?

No diagnostic is produced. Passing a literal object or array as a defineModel default silently creates shared state across component instances.

System Info

Any additional comments?

This was initially raised in vuejs/language-tools#6103.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions