fix(types): fix shallowReadonly type
This commit is contained in:
parent
eb721d49c0
commit
92f11d6740
@ -166,9 +166,7 @@ export function readonly<T extends object>(
|
|||||||
* returned properties.
|
* returned properties.
|
||||||
* This is used for creating the props proxy object for stateful components.
|
* This is used for creating the props proxy object for stateful components.
|
||||||
*/
|
*/
|
||||||
export function shallowReadonly<T extends object>(
|
export function shallowReadonly<T extends object>(target: T): Readonly<T> {
|
||||||
target: T
|
|
||||||
): Readonly<{ [K in keyof T]: UnwrapNestedRefs<T[K]> }> {
|
|
||||||
return createReactiveObject(
|
return createReactiveObject(
|
||||||
target,
|
target,
|
||||||
true,
|
true,
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { shallowReadonly } from '@vue/reactivity'
|
||||||
import { ref, readonly, describe, expectError, expectType, Ref } from './index'
|
import { ref, readonly, describe, expectError, expectType, Ref } from './index'
|
||||||
|
|
||||||
describe('should support DeepReadonly', () => {
|
describe('should support DeepReadonly', () => {
|
||||||
@ -13,3 +14,11 @@ describe('readonly ref', () => {
|
|||||||
const r = readonly(ref({ count: 1 }))
|
const r = readonly(ref({ count: 1 }))
|
||||||
expectType<Ref>(r)
|
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
|
||||||
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user