Skip to content
Permalink
Browse files
fix(types): handle ToRef<any>
fix #5188
  • Loading branch information
yyx990803 committed Jan 16, 2022
1 parent 6cfd72e commit 5ac703055fa83cb1e8a173bbd6a4d6c33707a3c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
@@ -1,6 +1,6 @@
import { isTracking, trackEffects, triggerEffects } from './effect'
import { TrackOpTypes, TriggerOpTypes } from './operations'
import { isArray, hasChanged } from '@vue/shared'
import { isArray, hasChanged, IfAny } from '@vue/shared'
import { isProxy, toRaw, isReactive, toReactive } from './reactive'
import type { ShallowReactiveMarker } from './reactive'
import { CollectionTypes } from './collectionHandlers'
@@ -222,7 +222,7 @@ class ObjectRefImpl<T extends object, K extends keyof T> {
}
}

export type ToRef<T> = [T] extends [Ref] ? T : Ref<T>
export type ToRef<T> = IfAny<T, Ref<T>, [T] extends [Ref] ? T : Ref<T>>

export function toRef<T extends object, K extends keyof T>(
object: T,
@@ -222,6 +222,11 @@ expectType<Ref<string>>(p2.obj.k)

expectType<Ref<number>>(toRefResult.value.b)
expectType<Ref<number>>(toRefsResult.a.value.b)

// #5188
const props = { foo: 1 } as { foo: any }
const { foo } = toRefs(props)
expectType<Ref<any>>(foo)
}

// toRef default value

0 comments on commit 5ac7030

Please sign in to comment.