Skip to content

Commit

Permalink
fix(types): fix shallowReadonly type
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 10, 2022
1 parent eb721d4 commit 92f11d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 1 addition & 3 deletions packages/reactivity/src/reactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions test-dts/reactivity.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { shallowReadonly } from '@vue/reactivity'
import { ref, readonly, describe, expectError, expectType, Ref } from './index'

describe('should support DeepReadonly', () => {
Expand All @@ -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
})

0 comments on commit 92f11d6

Please sign in to comment.