Backtestsvuerun-20261021-133314#9546

Issue #9546 Merged fix PR #15523 Run 21 Oct 2026 · run-20261021-133314 vuejs/core

defineProps options object loses properties when using generics

Worse

The merged fix was judged better than our patch.

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

Both patches restore the missing optional keys, but only Patch A makes the resulting prop types usable. Patch A removes the conditional in `PropMethod` so `PropType<T>` is no longer a deferred type when `T` is a type parameter; this addresses the root cause (the deferral cascading into `RequiredKeys`/`OptionalKeys`) and also lets `InferPropType` resolve to `T`. The added `InferPropType` tweak (`unknown extends D ? V : D`) keeps the inferred value assignable to `V` when no default is present. The independent tests confirm it: all six pass, including the two that check `props.a` is `T | undefined` and `props.c` is `T`, and Patch A's own dts test asserts exact types (`T | null`, `T`, `T | undefined`) plus assignability of `props` to `{ bar: T }`. The `PropMethod` widening is low risk because the new member is structurally a subtype of the existing `{ (): T }` member, so unions and inference are unaffected for non-generic usage.

Patch B wraps the key-check conditionals in `{ p: T[K] }` so the key sets resolve, which fixes the symptom of dropped keys, but leaves the value type as an unresolved `InferPropType<PropType<T>, true>`. The independent tests show this directly: two tests fail on B because `InferPropType<PropType<T>, true> | undefined` is not assignable to `T | undefined`, meaning a generic component still cannot pass `props.a` where `T` is expected. That falls short of the issue's ask that 'the props be declared correctly'. Patch B's own tests only check key existence and `undefined` assignability, never that the types resolve to `T`, so they would not have caught this gap. B also touches more surface (`DefaultKeys`, `PublicRequiredKeys`) without closing the underlying deferral. Patch A is the more correct fix with stronger tests.

Four judges ruled on this ticket in parallel, and the verdict comes from counting their votes. Each saw the issue and the two patches, labelled A and B in random order (two of them saw ours as A), with issue links and version numbers removed. Where tests could check the fix, they also saw the results of tests a separate agent wrote for the issue, run on both patches. None was told which patch was ours. The reasoning above is one judge's, shown verbatim.

Solve

15m 58s

Wall-clock time in the container

Full test suite

No new failures

1,824 passed · 1 skipped · 1,825 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

165vs 54 merged

Changed lines, ours vs merged

Vue version

3.3.7 & 3.4.alpha

Link to minimal reproduction

https://play.vuejs.org/#eNqNUk1v2zAM/SuELt2Axj70MMBIi25DD9thLbYcdXFsxlVmUxolpxkC//fS8kfT9AO9UXyP5OOjDuqrc8muRZWppS/YuAAeQ+ugzqm61Cp4raBCQjaFPFdaXWkyjbMc4AB3bN3qv0PoYMO2gTPpdKapsOQDOAE9XEKJG0PYU/2ngyaAPIPb9RaLALmfWyxXV+eaenidQaQBBMm/we0J3VhQfKRAuD2D8V9rGMsMArcYk52m7nPfKQpO8ilYT0GhaZkO5shcda6G/RdN7pKttyTexfl6BMSyWZFWYkn/1uo+BOezNC1KkrISa7PjhDCk5Jr0WmgptxRMg4vSNtcXyUXyJS2ND8fpBH2zWLN98MjSRKtxrTgmleQOecFIJTLyR8eelB2PPoFejJ/8E1OCl7NvTHViSWEbZ2rkWxeMfItn1uR1bR9+xtx8jVhzj8XfV/Jbvx92umOMyo72DzlXGAb45s8v3Es8g40t23o8wxvgb/S2bnuNA+1bS6XIPuJFtT/ihQ1VK3+zD0h+WqoXOn3K8R7f31n9Sa64PbvYPQLEQTNC

Steps to reproduce

<img width="443" alt="image" src="https://github.com/vuejs/core/assets/4620458/71dad487-a49c-4c18-8fa1-05851ec62fd2">

<script setup lang="ts" generic="T">
import { PropType } from 'vue'
const props = defineProps({
  a: Object as PropType<T>,

  b: {
    type: Object as PropType<T>
  },

  c: {
    type: Object as PropType<T>,
    required: true,
  }
})

props.a
props.b
props.c
</script>

What is expected?

The props to be declared correctly

What is actually happening?

Properties are been excluded from props, unless they are required 🤔

System Info

_No response_

Any additional comments?

_No response_

The two patches

Our patch+151 −14
packages-private/dts-test/defineComponent.test-d.tsxindex 2c31c5d29..55034ce9d 100644@@ -1331,6 +1331,43 @@ describe('prop starting with `on*` is broken', () => {   }) }) +describe('options with generic PropType', <T extends unknown>() => {+  const Comp = defineComponent({+    props: {+      a: Object as PropType<T>,+      b: {+        type: Object as PropType<T>,+      },+      c: {+        type: Object as PropType<T>,+        required: true,+      },+      d: {+        type: Object as PropType<T>,+        default: () => ({}),+      },+    },+    setup(props) {+      // optional props must not be dropped+      props.a+      props.b+      props.c+      props.d+      // @ts-expect-error+      props.e+    },+  })++  // props with defaults must not drop the other props from $props+  const { $props } = new Comp()+  $props.a+  $props.b+  $props.c+  $props.d+  // @ts-expect-error+  $props.e+})+ describe('function syntax w/ generics', () => {   const Comp = defineComponent(     // TODO: babel plugin to auto infer runtime props options from typepackages-private/dts-test/extractProps.test-d.tsindex 3a5acc66e..5815fec18 100644@@ -1,5 +1,10 @@-import type { ExtractPropTypes, ExtractPublicPropTypes } from 'vue'-import { type Prettify, expectType } from './utils'+import type {+  ExtractDefaultPropTypes,+  ExtractPropTypes,+  ExtractPublicPropTypes,+  PropType,+} from 'vue'+import { type Prettify, describe, expectType } from './utils'  const propsOptions = {   foo: {@@ -28,3 +33,55 @@ expectType<number | undefined>(publicProps.foo) expectType<string>(publicProps.bar) expectType<boolean | undefined>(publicProps.baz) expectType<unknown[] | undefined>(publicProps.qux)++describe('generic PropType', <T>() => {+  const genericPropsOptions = {+    a: Object as PropType<T>,+    b: {+      type: Object as PropType<T>,+    },+    c: {+      type: Object as PropType<T>,+      required: true,+    },+    d: {+      type: Object as PropType<T>,+      default: () => ({}),+    },+  } as const++  // internal facing props+  const props = {} as Prettify<ExtractPropTypes<typeof genericPropsOptions>>+  props.a+  props.b+  props.c+  props.d+  // @ts-expect-error+  props.e+  const a: typeof props.a = undefined+  const b: typeof props.b = undefined+  // @ts-expect-error required prop can't be undefined+  const c: typeof props.c = undefined++  // external facing props+  const publicProps = {} as Prettify<+    ExtractPublicPropTypes<typeof genericPropsOptions>+  >+  publicProps.a+  publicProps.b+  publicProps.c+  publicProps.d+  const pd: typeof publicProps.d = undefined+  // @ts-expect-error required prop can't be undefined+  const pc: typeof publicProps.c = undefined++  // props with defaults+  const defaults = {} as ExtractDefaultPropTypes<typeof genericPropsOptions>+  defaults.d+  // @ts-expect-error+  defaults.a+  // @ts-expect-error+  defaults.c++  a && b && c && pd && pc+})packages-private/dts-test/setupHelpers.test-d.tsindex 067b81b03..81ee4c077 100644@@ -299,6 +299,41 @@ describe('defineProps w/ runtime declaration', () => {   props2.baz }) +describe('defineProps w/ runtime declaration + generic PropType', <T>() => {+  const props = defineProps({+    a: Object as PropType<T>,+    b: {+      type: Object as PropType<T>,+    },+    c: {+      type: Object as PropType<T>,+      required: true,+    },+    d: {+      type: Object as PropType<T>,+      default: () => ({}),+    },+    e: Boolean,+  })++  // optional props must not be dropped+  props.a+  props.b+  props.c+  props.d+  expectType<boolean>(props.e)++  // optional props can be undefined+  const a: typeof props.a = undefined+  const b: typeof props.b = undefined+  // @ts-expect-error required prop can't be undefined+  const c: typeof props.c = undefined+  a && b && c++  // @ts-expect-error+  props.f+})+ describe('defineEmits w/ type declaration', () => {   const emit = defineEmits<(e: 'change') => void>()   emit('change')packages/runtime-core/src/componentProps.tsindex 94782e17c..2b0260db6 100644@@ -78,13 +78,19 @@ type PropMethod<T, TConstructor = any> = [T] extends [   ? { new (): TConstructor; (): T; readonly prototype: TConstructor } // Create Function like constructor   : never +// Prop options are wrapped in an object (`{ p: T[K] }`) before being matched+// against option shapes. A bare generic `PropType<T>` (e.g. in+// `<script setup generic="T">`) would otherwise defer the conditional, which in+// turn defers every key set derived from it and drops those props entirely. type RequiredKeys<T> = {-  [K in keyof T]: T[K] extends-    | { required: true }-    | { default: any }-    // don't mark Boolean props as undefined-    | BooleanConstructor-    | { type: BooleanConstructor }+  [K in keyof T]: { p: T[K] } extends {+    p:+      | { required: true }+      | { default: any }+      // don't mark Boolean props as undefined+      | BooleanConstructor+      | { type: BooleanConstructor }+  }     ? T[K] extends { default: undefined | (() => undefined) }       ? never       : K@@ -94,11 +100,13 @@ type RequiredKeys<T> = { type OptionalKeys<T> = Exclude<keyof T, RequiredKeys<T>>  type DefaultKeys<T> = {-  [K in keyof T]: T[K] extends-    | { default: any }-    // Boolean implicitly defaults to false-    | BooleanConstructor-    | { type: BooleanConstructor }+  [K in keyof T]: { p: T[K] } extends {+    p:+      | { default: any }+      // Boolean implicitly defaults to false+      | BooleanConstructor+      | { type: BooleanConstructor }+  }     ? T[K] extends { type: BooleanConstructor; required: true } // not default if Boolean is marked as required       ? never       : K@@ -151,7 +159,7 @@ export type ExtractPropTypes<O> = { }  type PublicRequiredKeys<T> = {-  [K in keyof T]: T[K] extends { required: true } ? K : never+  [K in keyof T]: { p: T[K] } extends { p: { required: true } } ? K : never }[keyof T]  type PublicOptionalKeys<T> = Exclude<keyof T, PublicRequiredKeys<T>> 
Merged fix · PR #15523+48 −6
packages-private/dts-test/setupHelpers.test-d.tsindex 067b81b03..6402aea3e 100644@@ -299,6 +299,40 @@ describe('defineProps w/ runtime declaration', () => {   props2.baz }) +describe('defineProps w/ runtime declaration + generic PropType', <T extends+  Record<string, any>>() => {+  // #9546+  const props = defineProps({+    foo: {+      type: Object as PropType<T>,+      required: false,+      default: null,+    },+    bar: {+      type: Object as PropType<T>,+      required: true,+    },+    baz: Object as PropType<T>,+    qux: String,+  })+  expectType<'foo' | 'bar' | 'baz' | 'qux'>(null! as keyof typeof props)+  expectType<T | null>(props.foo)+  expectType<T>(props.bar)+  expectType<T | undefined>(props.baz)+  expectType<string | undefined>(props.qux)++  // @ts-expect-error should not be a string+  expectType<string>(props.foo)+  // @ts-expect-error should not be a string+  expectType<string>(props.bar)+  // @ts-expect-error should not be a string+  expectType<string>(props.baz)++  // #9277: props should be usable where `T` is expected+  const use = (p: { bar: T }) => p+  use(props)+})+ describe('defineEmits w/ type declaration', () => {   const emit = defineEmits<(e: 'change') => void>()   emit('change')packages/runtime-core/src/componentProps.tsindex 94782e17c..eccb28a6c 100644@@ -72,11 +72,16 @@ export type PropType<T> = PropConstructor<T> | (PropConstructor<T> | null)[] type PropConstructor<T = any> =   { new (...args: any[]): T & {} } | { (): T } | PropMethod<T> -type PropMethod<T, TConstructor = any> = [T] extends [-  ((...args: any) => any) | undefined,-] // if is function with args, allowing non-required functions-  ? { new (): TConstructor; (): T; readonly prototype: TConstructor } // Create Function like constructor-  : never+// Function-like constructor so that `Function as PropType<() => void>`+// type-checks. Intentionally not conditional on `T`: a conditional type here+// makes `PropType<T>` a deferred (generic) type whenever `T` is a type+// parameter, which in turn defers `RequiredKeys` / `OptionalKeys` and drops+// every non-required prop from `ExtractPropTypes` (#9546).+type PropMethod<T, TConstructor = any> = {+  new (): TConstructor+  (): T+  readonly prototype: TConstructor+}  type RequiredKeys<T> = {   [K in keyof T]: T[K] extends@@ -124,7 +129,10 @@ type InferPropType<T, NullAsAny = true> = [T] extends [null]             : [T] extends [Prop<infer V, infer D>]               ? unknown extends V                 ? keyof V extends never-                  ? IfAny<V, V, D>+                  ? // `D` is only meaningful when a default is present; falling+                    // back to `V` keeps the deferred type assignable to `V`+                    // when `V` is a type parameter (#9546)+                    IfAny<V, V, unknown extends D ? V : D>                   : V                 : V               : T