fix(types): allow customRef to have different getter/setter types#14639
Conversation
fix vuejs#14637) The customRef function now supports two type parameters <T, S> like Ref<T, S>, allowing the getter to return type T while the setter accepts type S. Previously, CustomRefFactory only accepted a single type parameter T, which was used for both getter and setter. This prevented use cases where the setter should accept a different type than what the getter returns (e.g., parsing or transformation scenarios).
📝 WalkthroughWalkthroughThe changes add support for distinct getter and setter types in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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
|
Problem
The customRef function only accepted a single type parameter T, which was used for both getter and setter. This prevented use cases where the setter should accept a different type than what the getter returns.
Solution
Updated CustomRefFactory, CustomRefImpl, and customRef to support two type parameters <T, S = T>, matching the Ref<T, S> interface that already supports this.
Changes
Backward Compatibility
This is fully backward compatible since S defaults to T.
Fixes #14637
Summary by CodeRabbit
customRefnow supports distinct getter and setter types, enabling more precise type control when creating custom references with different input and output type requirements.