]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(types): fix shallowReadonly type
authorEvan You <yyx990803@gmail.com>
Mon, 10 Jan 2022 07:05:07 +0000 (15:05 +0800)
committerEvan You <yyx990803@gmail.com>
Mon, 10 Jan 2022 07:05:09 +0000 (15:05 +0800)
packages/reactivity/src/reactive.ts
test-dts/reactivity.test-d.ts

index b56cb3627b5b8c0bc96b7ad102893a840f87f73d..4716230e40f4972c79277707d90b5746af6acdc2 100644 (file)
@@ -166,9 +166,7 @@ export function readonly<T extends object>(
  * returned properties.
  * This is used for creating the props proxy object for stateful components.
  */
-export function shallowReadonly<T extends object>(
-  target: T
-): Readonly<{ [K in keyof T]: UnwrapNestedRefs<T[K]> }> {
+export function shallowReadonly<T extends object>(target: T): Readonly<T> {
   return createReactiveObject(
     target,
     true,
index 3c35ea58a01636485696f45af7bba54c1e65812d..4c22765e742f740245f06824fe3bda4655926622 100644 (file)
@@ -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<Ref>(r)
 })
+
+describe('shallowReadonly ref unwrap', () => {
+  const r = shallowReadonly({ count: { n: ref(1) } })
+  // @ts-expect-error
+  r.count = 2
+  expectType<Ref>(r.count.n)
+  r.count.n.value = 123
+})