From: Evan You Date: Mon, 10 Jan 2022 07:05:07 +0000 (+0800) Subject: fix(types): fix shallowReadonly type X-Git-Tag: v3.2.27~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=92f11d6740929f5b591740e30ae5fba50940ec82;p=thirdparty%2Fvuejs%2Fcore.git fix(types): fix shallowReadonly type --- diff --git a/packages/reactivity/src/reactive.ts b/packages/reactivity/src/reactive.ts index b56cb3627b..4716230e40 100644 --- a/packages/reactivity/src/reactive.ts +++ b/packages/reactivity/src/reactive.ts @@ -166,9 +166,7 @@ export function readonly( * returned properties. * This is used for creating the props proxy object for stateful components. */ -export function shallowReadonly( - target: T -): Readonly<{ [K in keyof T]: UnwrapNestedRefs }> { +export function shallowReadonly(target: T): Readonly { return createReactiveObject( target, true, diff --git a/test-dts/reactivity.test-d.ts b/test-dts/reactivity.test-d.ts index 3c35ea58a0..4c22765e74 100644 --- a/test-dts/reactivity.test-d.ts +++ b/test-dts/reactivity.test-d.ts @@ -1,3 +1,4 @@ +import { shallowReadonly } from '@vue/reactivity' import { ref, readonly, describe, expectError, expectType, Ref } from './index' describe('should support DeepReadonly', () => { @@ -13,3 +14,11 @@ describe('readonly ref', () => { const r = readonly(ref({ count: 1 })) expectType(r) }) + +describe('shallowReadonly ref unwrap', () => { + const r = shallowReadonly({ count: { n: ref(1) } }) + // @ts-expect-error + r.count = 2 + expectType(r.count.n) + r.count.n.value = 123 +})