Backtestsvuerun-20261002-115633#9546

Issue #9546 Merged fix PR #15523 Run 2 Oct 2026 · run-20261002-115633 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 make the same root-cause fix. They replace the conditional `PropMethod<T>` with a plain function-like constructor type. The old conditional became a deferred generic conditional whenever `T` was a type parameter. That deferral is what made `RequiredKeys`/`OptionalKeys` unresolvable and dropped the non-required props. Removing the conditional lets the props object's member types be treated as ordinary (non-generic-object) types, so key partitioning resolves again.

Patch A then makes one small, well-commented change to `InferPropType`. When no default is present, it falls back to `V` instead of `D`, so the still-deferred `unknown extends V` / `IfAny` chain stays assignable to `V`. This is low-risk: when `D` is `unknown` (no default), `V` and `D` were effectively the same fallback before. Its test covers the issue's three shapes (shorthand, `{type}`, `{type, required: true}`), a `default: null` case, a plain `String` prop, and assignability to `{ bar: T }`.

Patch B goes further, and that adds risk:
- It rewrites `OptionalKeys` and `PublicOptionalKeys` as per-key `Pick`-based mapped types. This changes core key-partitioning logic that every component uses, and it isn't needed once `PropMethod` is fixed.
- It inserts a new early `InferPropType` branch that infers `V` from `PropType<infer V> | { type: PropType<infer V>; default?: undefined }`. That bypasses the existing `unknown extends V` / `IfAny` handling for every non-default prop, not just generic ones. Inference from the constructor union (e.g. `StringConstructor`, `NumberConstructor`, custom classes, `Function` types) could now yield different results, such as wrapper types vs. primitives or the `T & {}` form. This broad behavioral change on hot type paths is likely to cause subtle regressions elsewhere.

Patch B's tests are more extensive (`defineComponent`, `ExtractPropTypes`/`ExtractPublicPropTypes`, a `Function` prop), which is a real plus. But they don't offset the riskier, more invasive type-level changes. Patch A fixes the reported issue at its root with a minimal, targeted change and adequate tests, so it is the better patch.

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

22m

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

129vs 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+115 −14
packages-private/dts-test/defineComponent.test-d.tsxindex 2c31c5d29..83868680f 100644@@ -384,6 +384,29 @@ describe('type inference w/ optional props declaration', () => {   ;<MyComponent msg="1" /> }) +// #9546+describe('type inference w/ generic runtime props', <T extends unknown>() => {+  defineComponent({+    props: {+      a: Object as PropType<T>,+      b: {+        type: Object as PropType<T>,+      },+      c: {+        type: Object as PropType<T>,+        required: true,+      },+    },+    setup(props) {+      expectType<T | undefined>(props.a)+      expectType<T | undefined>(props.b)+      expectType<T>(props.c)+      // @ts-expect-error should not be any+      expectType<number>(props.a)+    },+  })+})+ describe('type inference w/ direct setup function', () => {   const MyComponent = defineComponent((_props: { msg: string }) => () => {})   expectType<JSX.Element>(<MyComponent msg="foo" />)packages-private/dts-test/extractProps.test-d.tsindex 3a5acc66e..cdd686b85 100644@@ -1,4 +1,4 @@-import type { ExtractPropTypes, ExtractPublicPropTypes } from 'vue'+import type { ExtractPropTypes, ExtractPublicPropTypes, PropType } from 'vue' import { type Prettify, expectType } from './utils'  const propsOptions = {@@ -28,3 +28,34 @@ expectType<number | undefined>(publicProps.foo) expectType<string>(publicProps.bar) expectType<boolean | undefined>(publicProps.baz) expectType<unknown[] | undefined>(publicProps.qux)++// #9546+function extractGenericProps<T>() {+  const genericPropsOptions = {+    a: Object as PropType<T>,+    b: {+      type: Object as PropType<T>,+    },+    c: {+      type: Object as PropType<T>,+      required: true,+    },+  } as const++  const props = {} as Prettify<ExtractPropTypes<typeof genericPropsOptions>>+  expectType<T | undefined>(props.a)+  expectType<T | undefined>(props.b)+  expectType<T>(props.c)+  // @ts-expect-error should not be any+  expectType<number>(props.a)++  const publicProps = {} as Prettify<+    ExtractPublicPropTypes<typeof genericPropsOptions>+  >+  expectType<T | undefined>(publicProps.a)+  expectType<T | undefined>(publicProps.b)+  expectType<T>(publicProps.c)+  // @ts-expect-error c is required+  const missingRequired: ExtractPublicPropTypes<typeof genericPropsOptions> = {}+}+extractGenericProps()packages-private/dts-test/setupHelpers.test-d.tsindex 067b81b03..0d825ed72 100644@@ -299,6 +299,35 @@ describe('defineProps w/ runtime declaration', () => {   props2.baz }) +// #9546+describe('defineProps w/ runtime declaration + generics', <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: Function as PropType<(value: T) => void>,+    },+    e: String,+  })+  expectType<T | undefined>(props.a)+  expectType<T | undefined>(props.b)+  expectType<T>(props.c)+  expectType<((value: T) => void) | undefined>(props.d)+  expectType<string | undefined>(props.e)+  // @ts-expect-error should not be any+  expectType<number>(props.a)+  // @ts-expect-error optional props can be undefined+  expectType<T>(props.b)+  // @ts-expect-error should be readonly+  props.c = {} as T+})+ describe('defineEmits w/ type declaration', () => {   const emit = defineEmits<(e: 'change') => void>()   emit('change')packages/runtime-core/src/componentProps.tsindex 94782e17c..cae6ff3ab 100644@@ -72,11 +72,14 @@ 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, allows `Function as PropType<(...args) => any>`.+// Intentionally not a conditional type on T: that would leave every+// `PropType<T>` unresolvable when T is a generic type parameter.+type PropMethod<T, TConstructor = any> = {+  new (): TConstructor+  (): T+  readonly prototype: TConstructor+}  type RequiredKeys<T> = {   [K in keyof T]: T[K] extends@@ -91,7 +94,12 @@ type RequiredKeys<T> = {     : never }[keyof T] -type OptionalKeys<T> = Exclude<keyof T, RequiredKeys<T>>+// resolve each key on its own instead of `Exclude<keyof T, RequiredKeys<T>>`,+// so that a key whose requiredness can't be resolved yet (e.g. it depends on+// a generic type parameter) doesn't make all other keys unresolvable as well+type OptionalKeys<T> = {+  [K in keyof T]-?: K extends RequiredKeys<Pick<T, K>> ? never : K+}[keyof T]  type DefaultKeys<T> = {   [K in keyof T]: T[K] extends@@ -121,13 +129,21 @@ type InferPropType<T, NullAsAny = true> = [T] extends [null]             ? U extends DateConstructor               ? 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>+            : // without a default, the explicit type is the result; skip the+              // `unknown extends V` check below, which can never be resolved+              // when V is a generic type parameter+              [T] extends [+                  | PropType<infer V>+                  | { type: PropType<infer V>; default?: undefined },+                ]+              ? V+              : [T] extends [Prop<infer V, infer D>]+                ? unknown extends V+                  ? keyof V extends never+                    ? IfAny<V, V, D>+                    : V                   : V-                : V-              : T+                : T  /**  * Extract prop types from a runtime props options object.@@ -154,7 +170,9 @@ type PublicRequiredKeys<T> = {   [K in keyof T]: T[K] extends { required: true } ? K : never }[keyof T] -type PublicOptionalKeys<T> = Exclude<keyof T, PublicRequiredKeys<T>>+type PublicOptionalKeys<T> = {+  [K in keyof T]-?: K extends PublicRequiredKeys<Pick<T, K>> ? never : K+}[keyof T]  /**  * Extract prop types from a runtime props options object. 
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