Backtestsvuerun-20261003-231210#9546

Issue #9546 Merged fix PR #15523 Run 3 Oct 2026 · run-20261003-231210 vuejs/core

defineProps options object loses properties when using generics

Better

Our patch was judged better than the merged fix.

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

Both patches make the same root-cause change. They remove the conditional in `PropMethod`, which was making `PropType<T>` a deferred generic and causing `RequiredKeys`/`OptionalKeys` to drop non-required props. Both therefore restore the missing keys `a` and `b`. They differ in how `InferPropType` resolves the value type.

Patch A short-circuits when no default is present (`unknown extends D`) and returns `V` directly. A generic `T` then resolves cleanly to `T` instead of getting stuck in the deferred `unknown extends V` check. When a default exists or `D` is `any`, it falls back to the original logic via `InferPropValueType`. Tracing the non-generic cases (V = unknown, {}, any, concrete types), the behavior is identical to before, so regression risk is low.

Patch B only tweaks the innermost `IfAny` branch. The result is still a deferred conditional (`unknown extends T ? ... : T`) that happens to be assignable to `T` because every branch collapses to `T`. This works for assignability but leaves an unresolved conditional type in the props. That is less clean for hover display, inference and further type manipulation, and it fixes the symptom more than it normalizes the type.

On tests, Patch A is broader. It covers `ExtractPropTypes`, `ExtractPublicPropTypes`, `ExtractDefaultPropTypes`, `defineComponent` and `defineProps`, all with generics. Patch B adds a single `defineProps` test, though it usefully includes a `default: null` case and a negative check against `string`.

Overall, Patch A gives a more direct resolution of generic prop types and more thorough test coverage at similar scope.

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

16m 36s

Wall-clock time in the container

Full test suite

No new failures

3,743 passed · 6 skipped · 3,749 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

113vs 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+102 −11
packages-private/dts-test/defineComponent.test-d.tsxindex 2c31c5d29..ddc28d8d7 100644@@ -366,6 +366,28 @@ describe('with object props', () => {   }) }) +describe('with object props w/ generics', () => {+  function test<T>() {+    return defineComponent({+      props: {+        a: Object as PropType<T>,+        b: { type: Object as PropType<T> },+        c: { type: Object as PropType<T>, required: true },+        d: String,+      },+      setup(props) {+        expectType<T | undefined>(props.a)+        expectType<T | undefined>(props.b)+        expectType<T>(props.c)+        expectType<string | undefined>(props.d)+        // @ts-expect-error+        props.e+      },+    })+  }+  test()+})+ describe('type inference w/ optional props declaration', () => {   const MyComponent = defineComponent<{ a: string[]; msg: string }>({     setup(props) {packages-private/dts-test/extractProps.test-d.tsindex 3a5acc66e..37685a408 100644@@ -1,4 +1,9 @@-import type { ExtractPropTypes, ExtractPublicPropTypes } from 'vue'+import type {+  ExtractDefaultPropTypes,+  ExtractPropTypes,+  ExtractPublicPropTypes,+  PropType,+} from 'vue' import { type Prettify, expectType } from './utils'  const propsOptions = {@@ -28,3 +33,33 @@ expectType<number | undefined>(publicProps.foo) expectType<string>(publicProps.bar) expectType<boolean | undefined>(publicProps.baz) expectType<unknown[] | undefined>(publicProps.qux)++// generic prop types+function genericProps<T>() {+  const genericPropsOptions = {+    a: Object as PropType<T>,+    b: { type: Object as PropType<T> },+    c: { type: Object as PropType<T>, required: true },+    d: { type: String, default: 'd' },+  } as const++  const props = {} as ExtractPropTypes<typeof genericPropsOptions>+  expectType<T | undefined>(props.a)+  expectType<T | undefined>(props.b)+  expectType<T>(props.c)+  expectType<string>(props.d)++  const publicProps = {} as ExtractPublicPropTypes<typeof genericPropsOptions>+  expectType<T | undefined>(publicProps.a)+  expectType<T | undefined>(publicProps.b)+  expectType<T>(publicProps.c)+  expectType<string | undefined>(publicProps.d)++  const defaultProps = {} as ExtractDefaultPropTypes<+    typeof genericPropsOptions+  >+  expectType<string>(defaultProps.d)+  // @ts-expect-error+  defaultProps.a+}+genericProps()packages-private/dts-test/setupHelpers.test-d.tsindex 067b81b03..34f801ebf 100644@@ -54,6 +54,28 @@ describe('defineProps w/ generics', () => {   test() }) +describe('defineProps w/ runtime declaration + generics', () => {+  function test<T>() {+    const props = defineProps({+      a: Object as PropType<T>,+      b: { type: Object as PropType<T> },+      c: { type: Object as PropType<T>, required: true },+      d: String,+      e: { type: Boolean },+      f: { type: Number, default: 1 },+    })+    expectType<T | undefined>(props.a)+    expectType<T | undefined>(props.b)+    expectType<T>(props.c)+    expectType<string | undefined>(props.d)+    expectType<boolean>(props.e)+    expectType<number>(props.f)+    // @ts-expect-error+    props.g+  }+  test()+})+ describe('defineProps w/ type declaration + withDefaults', <T extends   string>() => {   const res = withDefaults(packages/runtime-core/src/componentProps.tsindex 94782e17c..ce01835cf 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, allowing `Function as PropType<(...args) => any>`.+// Intentionally not a conditional type on `T`: that would be deferred when `T`+// is a generic type parameter and make every `PropType<T>` unresolvable in+// prop type inference (e.g. `defineProps` in `<script setup generic="T">`).+// It is a subtype of `{ (): T }`, so it does not widen what is assignable.+type PropMethod<T, TConstructor = any> = {+  new (): TConstructor+  (): T+  readonly prototype: TConstructor+}  type RequiredKeys<T> = {   [K in keyof T]: T[K] extends@@ -122,13 +127,20 @@ type InferPropType<T, NullAsAny = true> = [T] extends [null]               ? Date | InferPropType<U, false>               : InferPropType<U, false>             : [T] extends [Prop<infer V, infer D>]-              ? unknown extends V-                ? keyof V extends never-                  ? IfAny<V, V, D>-                  : V-                : V+              ? // without a default value (`D` is `unknown`) the result is+                // always `V`, return it directly so that a generic `V` does not+                // get stuck in the deferred `unknown extends V` check below+                unknown extends D+                ? IfAny<D, InferPropValueType<V, D>, V>+                : InferPropValueType<V, D>               : T +type InferPropValueType<V, D> = unknown extends V+  ? keyof V extends never+    ? IfAny<V, V, D>+    : V+  : V+ /**  * Extract prop types from a runtime props options object.  * The extracted types are **internal** - i.e. the resolved props received by 
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