Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(types): handle ToRef<any>
fix #5188
  • Loading branch information
yyx990803 committed Jan 16, 2022
1 parent 6cfd72e commit 5ac7030
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/reactivity/src/ref.ts
@@ -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'
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions test-dts/ref.test-d.ts
Expand Up @@ -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
Expand Down

0 comments on commit 5ac7030

Please sign in to comment.