From: Evan You Date: Sun, 16 Jan 2022 07:46:49 +0000 (+0800) Subject: fix(types): handle ToRef X-Git-Tag: v3.2.27~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5ac703055fa83cb1e8a173bbd6a4d6c33707a3c3;p=thirdparty%2Fvuejs%2Fcore.git fix(types): handle ToRef fix #5188 --- diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 55059485d6..c972676ac4 100644 --- a/packages/reactivity/src/ref.ts +++ b/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' @@ -222,7 +222,7 @@ class ObjectRefImpl { } } -export type ToRef = [T] extends [Ref] ? T : Ref +export type ToRef = IfAny, [T] extends [Ref] ? T : Ref> export function toRef( object: T, diff --git a/test-dts/ref.test-d.ts b/test-dts/ref.test-d.ts index f91d6415f7..e585470d5e 100644 --- a/test-dts/ref.test-d.ts +++ b/test-dts/ref.test-d.ts @@ -222,6 +222,11 @@ expectType>(p2.obj.k) expectType>(toRefResult.value.b) expectType>(toRefsResult.a.value.b) + + // #5188 + const props = { foo: 1 } as { foo: any } + const { foo } = toRefs(props) + expectType>(foo) } // toRef default value