ToRef types Error
Version
3.2.26
Reproduction link
about:blank
Steps to reproduce
function setup<T>(props: { value: T }) {
const value = toRef(props,'value')
}
What is expected?
typeof value.value
should be V
What is actually happening?
typeof value.value
is any
may be change defination
- type ToRef<T> = [T] extends [Ref] ? T : Ref<T>;
+ type ToRef<T> = [T] extends [Ref<T>] ? T : Ref<T>;
Do you have an actual reproduction? Because this seems to work:
defineComponent({
props: {
value: String
},
setup(props) {
const a = toRef(props, 'value')
a.value
}
})
Do you have an actual reproduction? Because this seems to work:
defineComponent({ props: { value: String }, setup(props) { const a = toRef(props, 'value') a.value } })
You can try this
import { defineComponent, PropType, toRef } from "vue";
export const MyComponent = <T extends string | number>() => {
return defineComponent({
props: {
value: null as unknown as PropType<T>
},
setup: (props) => {
const value = toRef(props, 'value')
return () => <>{
value.value
}</>;
}
});
};