Repository navigation
fix(types): keep optional props when a runtime prop uses a generic PropType - #15523
Conversation
…opType `PropMethod<T>` was a conditional type on `T`, so `PropType<T>` became a deferred generic type inside `<script setup generic="T">`. That deferred `RequiredKeys` / `OptionalKeys` for the whole options object and dropped every non-required prop (even plain `String` ones) from the inferred props. The prop value type also never resolved to `T`. Make `PropMethod` unconditional and fall back to `V` when no default type is inferred, so keys resolve eagerly and the value stays assignable to `T`. close vuejs#9546
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughGeneric runtime prop declarations now retain deferred generic types during prop extraction. The change updates constructor and default inference types and adds type tests for optional, required, defaulted, and built-in props. ChangesGeneric prop inference
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Suggested reviewers: Merge Risk: ⚪ Minimal · up to The generic runtime prop inference fix includes coverage for required, optional, defaulted, and built-in props, with no actionable merge risk identified. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
Size ReportBundles
Usages
|
|
/ecosystem-ci run |
|
📝 Ran ecosystem CI: Open
|
close #9546
Inside
<script setup lang="ts" generic="T">, a runtime props object that usesObject as PropType<T>lost every prop that was notrequired: true(even unrelated ones likequx: String), and the ones that survived never resolved toT.Cause.
PropMethod<T>is a conditional type onT. WhenTis a type parameter that conditional is deferred, which makes the wholePropType<T>union a generic type.RequiredKeys/OptionalKeysthen defer for the entire options object, soExtractPropTypesyields a generic mapped type and property access fails for everything on the optional side.InferPropType's[T] extends [Prop<infer V, infer D>]was deferred for the same reason.Fix.
PropMethoda plain object type. It only exists soFunction as PropType<() => void>type-checks; the conditional never changed what a cast accepts, since(): Tstill has to be comparable with the constructor's call signature.InferPropType, fall back toVwhen no default type was inferred (unknown extends D). For concrete types the result is unchanged; for a type parameter it keeps the deferred type's constraint atV, soprops.baris assignable toT.The added test is the case @pikax asked for in #9652, plus a bare
Object as PropType<T>prop, an unrelatedStringprop, and passingpropswhere{ bar: T }is expected (#9277). It fails onmainwith 5 errors and passes with this change; the rest ofdts-testandpnpm checkare unaffected.Summary by CodeRabbit
Bug Fixes
PropTypevalues.nullandundefinedhandling.Tests