Backtestsvuerun-20261005-155915#15096

Issue #15096 Merged fix PR #15097 Run 5 Oct 2026 · run-20261005-155915 vuejs/core

defineModel: named model with PropType + factory default infers wrong generic (regression from #14968)

Better

Our patch was judged better than the merged fix.

In this judgment, Patch A = our agent, Patch B = the merged fix.

Patch A fixes the root cause. It adds dedicated overloads for the case where a runtime `type: PropType<T>` is present together with `default`. In those overloads the default is typed as `DefineModelDefault<NoInfer<T>>`, so the factory `() => []` can no longer act as an inference candidate for `T`. `T` is therefore inferred only from `type`, which is exactly the inference-priority problem the issue describes. The overloads cover both the named and unnamed forms, and the default is still checked against the inferred `T`. Patch A's tests are broad: empty and non-empty arrays, objects, unions, function types, a plain `String` type, and an explicitly pinned generic. It also has negative cases: a mismatched factory return, a raw array default, and a primitive mismatch. One possible concern is that `NoInfer` in public typings requires TS 5.4 or later. However, the issue's environment uses TS 5.7, and the approach is a standard one.

Patch B only swaps the order of the intersection members, putting `DefineModelRuntimeOptions` before the default/required union. TypeScript's inference collects candidates from all intersection constituents and ranks them by inference priority, not by source order. The direct candidate from the `default` factory would still outrank the lower-priority candidate from `PropType<T>`, so this reordering is unlikely to change which `T` wins. At best it depends on fragile, undocumented ordering behavior. Its tests target the right scenario, but with no evidence they pass, the fix looks unreliable.

On correctness, which matters most, Patch A clearly wins, and it also has the stronger tests.

The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.

Solve

14m 24s

Wall-clock time in the container

Full test suite

No new failures

3,626 passed · 6 skipped · 3,632 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

83vs 26 merged

Changed lines, ours vs merged

Vue version

3.5.39

Link to minimal reproduction

https://play.vuejs.org/#eNqtk81qGzEQx19l0MUJmDXUTaGLbUhKDi20DY1JD1Gold3ZjWJZEvpwbcwee+sjtC/XJ+lIi50EQk65rWb+M/Obj92xU2uLdURWsomvnLQBPIZoQQndTjkLnrMZ13JljQsQthZhBxfO2Hn67KBxZgUDSjDgmuvRCP79/Q1nsS1hfglSN+g8zHtVuENY1NiIqMICGlEF47Ygg0fVkNQHFDWYBhapymKYs1UieqlbEOBtdNJE3zOgc8YBuSqEq4gwLk6K8fuC68pQIrh1ZokapkDlpMbPpkZ1NFhLL2+lkmE7GMKOa8i5Sjh1TmxB+ENfEx8cVb2+mREFpCSJuYSjY5jO4PqGrN3xvt8/v+C7cUvhTNR1CVbq3GmLGp2sADdWyUoGtd3DNXKD9VO2h4KPKd+8DuZk1C+W1kiPgCurREB6AUxquZ7tdvt5dR3Qo+fruskoeVP8IYYN6SCoi0a2xb03mq4mA3JWmZWVCt1XGyR1yVnZoyefUMr8/JRtwUXMsDnmDqvlM/Z7v0k2zi4cenRr5OzgC8K1GHr3+eUX3ND3wbkydVSkfsH5Db1RMTH2sjNaGmE/0mXaj/neabhzf74JqP2+qQSalF3Wc0aX/+GF1h9wx8XbHEc7oSn+WNOPQWoaYH+6yRb81cF6Urwrxqz7D9k1OqM=

Steps to reproduce

In the reproduction, broken declares a named model with a runtime type: PropType<string[]> plus a factory default: () => []. fixed declares the same thing but with the generic pinned explicitly (defineModel<string[]>(...)).

Run the type checker (or vue-tsc --noEmit locally) over this SFC.

What is expected?

Both broken and fixed should type-check cleanly — this is the recommended pattern for avoiding shared mutable state (per #14966 / #14968): a factory default combined with a runtime PropType declaration.

What is actually happening?

Only broken fails. TS infers the generic T from the default factory function's own type (() => never[]) instead of from the type: PropType<string[]> field:

error TS2769: No overload matches this call.
Overload 1 of 4, '(name: string, options: ({ required: true; } | { default: DefineModelDefault<() => never[]>; }) & Omit<PropOptions<() => never[], () => never[]>, "default"> & DefineModelOptions<...>): ModelRef<...>', gave the following error.
Type 'PropType<string[]>' is not assignable to type 'true | PropType<() => never[]> | null | undefined'.
Type 'new (...args: any[]) => string[]' is not assignable to type 'true | PropType<() => never[]> | null | undefined'.
Type 'new (...args: any[]) => string[]' is not assignable to type 'new (...args: any[]) => () => never[]'.
Type 'string[]' is not assignable to type '() => never[]'.
Type 'string[]' provides no match for the signature '(): never[]'.
Overload 2 of 4, '(name: string, options?: DefineModelRuntimeOptions<string[], string[], string[]> | undefined): ModelRef<string[] | undefined, string, string[] | undefined, string[] | undefined>', gave the following error.
Object literal may only specify known properties, and 'default' does not exist in type 'DefineModelRuntimeOptions<string[], string[], string[]>'.

his is a regression from #14968 (landed in 3.5.39), which introduced DefineModelDefault<T> = InferDefault<Data, T> for the named-model overload. When both a runtime type: PropType<T> field and a factory default are present on the same options object, TS resolves T from the default field first, breaking a pattern that worked prior to 3.5.39.

Workaround: explicitly pin the generic, as shown by fixed in the reproduction:

const fixed = defineModel<string[]>('visibility2', {
  type: Array as PropType<string[]>,
  default: () => [],
})

System Info

vue: 3.5.39
vue-tsc: 3.3.7
typescript: 5.7.3

Any additional comments?

Related to / regression from #14966 and #14968. Only reproduces on the named defineModel(name, options) overload when type/PropType and a factory default are combined; the unnamed defineModel<T>({ ... }) form with an explicit generic is unaffected.

The two patches

Our patch+83 −0
packages-private/dts-test/setupHelpers.test-d.tsindex 5ecc15443..4f5b448d8 100644@@ -1,4 +1,5 @@ import {+  type PropType,   type Ref,   type Slots,   type VNode,@@ -475,6 +476,67 @@ describe('defineModel', () => {   // @ts-expect-error unknown props option   defineModel({ foo: 123 }) +  // #15096 runtime type + factory default infers from `type`, not `default`+  {+    const named = defineModel('visibility', {+      type: Array as PropType<string[]>,+      default: () => [],+    })+    expectType<Ref<string[]>>(named)+    named.value = ['a']++    const unnamed = defineModel({+      type: Array as PropType<string[]>,+      default: () => [],+    })+    expectType<Ref<string[]>>(unnamed)++    const nonEmpty = defineModel('items', {+      type: Array as PropType<number[]>,+      default: () => [1],+    })+    expectType<Ref<number[]>>(nonEmpty)++    const obj = defineModel('obj', {+      type: Object as PropType<{ foo: string }>,+      default: () => ({ foo: 'bar' }),+    })+    expectType<Ref<{ foo: string }>>(obj)++    const union = defineModel('union', {+      type: [String, Array] as PropType<string | string[]>,+      default: () => ['a'],+    })+    expectType<Ref<string | string[]>>(union)++    const fn = defineModel('fn', {+      type: Function as PropType<(n: number) => string>,+      default: (n: number) => String(n),+    })+    expectType<Ref<(n: number) => string>>(fn)++    const str = defineModel('str', { type: String, default: 'a' })+    expectType<Ref<string>>(str)++    const pinned = defineModel<string[]>('pinned', {+      type: Array as PropType<string[]>,+      default: () => [],+    })+    expectType<Ref<string[]>>(pinned)++    // @ts-expect-error factory default must match runtime type+    defineModel('bad', {+      type: Array as PropType<string[]>,+      default: () => [1],+    })+    // @ts-expect-error factory default must match runtime type+    defineModel({ type: Array as PropType<string[]>, default: () => [1] })+    // @ts-expect-error raw array defaults must use a factory+    defineModel('bad', { type: Array as PropType<string[]>, default: [] })+    // @ts-expect-error default must match runtime type+    defineModel('bad', { type: String, default: 1 })+  }+   // unrelated getter and setter types   {     const modelVal = defineModel({packages/runtime-core/src/apiSetupHelpers.tsindex 7a1d2e3a2..7c0e0a626 100644@@ -30,6 +30,7 @@ import type {   ComponentPropsOptions,   ExtractPropTypes,   PropOptions,+  PropType, } from './componentProps' import { warn } from './warning' import type { SlotsType, StrictUnwrapSlotsType } from './componentSlots'@@ -275,6 +276,17 @@ type DefineModelRuntimeOptions<T, G, S> = Omit<PropOptions<T>, 'default'> &  type DefineModelDefault<T> = InferDefault<Data, T> +/**+ * When a runtime `type` is declared, `T` must be inferred from it alone.+ * Otherwise the `default` value (e.g. a factory `() => []`) would be picked as+ * an inference candidate for `T` and win over the lower-priority candidate+ * inferred from `type`.+ */+type DefineModelTypedDefaultOptions<T, G, S> = {+  type: PropType<T>+  default: DefineModelDefault<NoInfer<T>>+} & DefineModelRuntimeOptions<T, G, S>+ /**  * Vue `<script setup>` compiler macro for declaring a  * two-way binding prop that can be consumed via `v-model` from the parent@@ -308,6 +320,10 @@ type DefineModelDefault<T> = InferDefault<Data, T>  * const count = defineModel<number>('count', { default: 0 })  * ```  */+export function defineModel<T, M extends PropertyKey = string, G = T, S = T>(+  options: DefineModelTypedDefaultOptions<T, G, S>,+): ModelRef<T, M, G, S>+ export function defineModel<T, M extends PropertyKey = string, G = T, S = T>(   options: ({ default: DefineModelDefault<T> } | { required: true }) &     DefineModelRuntimeOptions<T, G, S>,@@ -317,6 +333,11 @@ export function defineModel<T, M extends PropertyKey = string, G = T, S = T>(   options?: DefineModelRuntimeOptions<T, G, S>, ): ModelRef<T | undefined, M, G | undefined, S | undefined> +export function defineModel<T, M extends PropertyKey = string, G = T, S = T>(+  name: string,+  options: DefineModelTypedDefaultOptions<T, G, S>,+): ModelRef<T, M, G, S>+ export function defineModel<T, M extends PropertyKey = string, G = T, S = T>(   name: string,   options: ({ default: DefineModelDefault<T> } | { required: true }) & 
Merged fix · PR #15097+22 −4
packages-private/dts-test/setupHelpers.test-d.tsindex 5ecc15443..067b81b03 100644@@ -1,4 +1,5 @@ import {+  type PropType,   type Ref,   type Slots,   type VNode,@@ -421,6 +422,18 @@ describe('defineModel', () => {   const countDefault = defineModel<number>('count', { default: 1 })   expectType<Ref<number>>(countDefault) +  const inferredNamedArrayDefault = defineModel('items', {+    type: Array as PropType<string[]>,+    default: () => [],+  })+  expectType<Ref<string[]>>(inferredNamedArrayDefault)++  const inferredArrayDefault = defineModel({+    type: Array as PropType<string[]>,+    default: () => [],+  })+  expectType<Ref<string[]>>(inferredArrayDefault)+   const arrayDefault = defineModel<number[]>({ default: () => [] })   expectType<Ref<number[]>>(arrayDefault) @@ -468,6 +481,11 @@ describe('defineModel', () => {    // @ts-expect-error type / default mismatch   defineModel<string>({ default: 123 })+  // @ts-expect-error runtime type / default mismatch+  defineModel('items', {+    type: Array as PropType<string[]>,+    default: () => [1],+  })   // @ts-expect-error raw array defaults must use a factory   defineModel<number[]>({ default: [] })   // @ts-expect-error raw object defaults must use a factorypackages/runtime-core/src/apiSetupHelpers.tsindex 7a1d2e3a2..f71616988 100644@@ -309,8 +309,8 @@ type DefineModelDefault<T> = InferDefault<Data, T>  * ```  */ export function defineModel<T, M extends PropertyKey = string, G = T, S = T>(-  options: ({ default: DefineModelDefault<T> } | { required: true }) &-    DefineModelRuntimeOptions<T, G, S>,+  options: DefineModelRuntimeOptions<T, G, S> &+    ({ default: DefineModelDefault<T> } | { required: true }), ): ModelRef<T, M, G, S>  export function defineModel<T, M extends PropertyKey = string, G = T, S = T>(@@ -319,8 +319,8 @@ export function defineModel<T, M extends PropertyKey = string, G = T, S = T>(  export function defineModel<T, M extends PropertyKey = string, G = T, S = T>(   name: string,-  options: ({ default: DefineModelDefault<T> } | { required: true }) &-    DefineModelRuntimeOptions<T, G, S>,+  options: DefineModelRuntimeOptions<T, G, S> &+    ({ default: DefineModelDefault<T> } | { required: true }), ): ModelRef<T, M, G, S>  export function defineModel<T, M extends PropertyKey = string, G = T, S = T>(