fix(toRef): ref created from union typed prop can't be used in watch (#3048)
This commit is contained in:
		
							parent
							
								
									6d5b623512
								
							
						
					
					
						commit
						4ca4666d58
					
				@ -20,7 +20,7 @@ export interface Ref<T = any> {
 | 
				
			|||||||
  _shallow?: boolean
 | 
					  _shallow?: boolean
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type ToRef<T> = T extends Ref ? T : Ref<UnwrapRef<T>>
 | 
					export type ToRef<T> = [T] extends [Ref] ? T : Ref<UnwrapRef<T>>
 | 
				
			||||||
export type ToRefs<T = any> = {
 | 
					export type ToRefs<T = any> = {
 | 
				
			||||||
  // #2687: somehow using ToRef<T[K]> here turns the resulting type into
 | 
					  // #2687: somehow using ToRef<T[K]> here turns the resulting type into
 | 
				
			||||||
  // a union of multiple Ref<*> types instead of a single Ref<* | *> type.
 | 
					  // a union of multiple Ref<*> types instead of a single Ref<* | *> type.
 | 
				
			||||||
 | 
				
			|||||||
@ -9,7 +9,8 @@ import {
 | 
				
			|||||||
  proxyRefs,
 | 
					  proxyRefs,
 | 
				
			||||||
  toRef,
 | 
					  toRef,
 | 
				
			||||||
  toRefs,
 | 
					  toRefs,
 | 
				
			||||||
  ToRefs
 | 
					  ToRefs,
 | 
				
			||||||
 | 
					  watch
 | 
				
			||||||
} from './index'
 | 
					} from './index'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function plainType(arg: number | Ref<number>) {
 | 
					function plainType(arg: number | Ref<number>) {
 | 
				
			||||||
@ -165,6 +166,14 @@ const obj = {
 | 
				
			|||||||
expectType<Ref<number>>(toRef(obj, 'a'))
 | 
					expectType<Ref<number>>(toRef(obj, 'a'))
 | 
				
			||||||
expectType<Ref<number>>(toRef(obj, 'b'))
 | 
					expectType<Ref<number>>(toRef(obj, 'b'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const objWithUnionProp: { a: string | number } = {
 | 
				
			||||||
 | 
					  a: 1
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					watch(toRef(objWithUnionProp, 'a'), value => {
 | 
				
			||||||
 | 
					  expectType<string | number>(value)
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// toRefs
 | 
					// toRefs
 | 
				
			||||||
const objRefs = toRefs(obj)
 | 
					const objRefs = toRefs(obj)
 | 
				
			||||||
expectType<{
 | 
					expectType<{
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user