mirror of https://github.com/vuejs/core.git
fix(types): calling readonly() with ref() should return Readonly<Ref<T>>
This commit is contained in:
parent
065c367175
commit
f3e3f1f93b
|
@ -438,7 +438,8 @@ describe('reactivity/readonly', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
test('should make ref readonly', () => {
|
test('should make ref readonly', () => {
|
||||||
const n: any = readonly(ref(1))
|
const n = readonly(ref(1))
|
||||||
|
// @ts-expect-error
|
||||||
n.value = 2
|
n.value = 2
|
||||||
expect(n.value).toBe(1)
|
expect(n.value).toBe(1)
|
||||||
expect(
|
expect(
|
||||||
|
|
|
@ -139,7 +139,7 @@ export type DeepReadonly<T> = T extends Builtin
|
||||||
: T extends Promise<infer U>
|
: T extends Promise<infer U>
|
||||||
? Promise<DeepReadonly<U>>
|
? Promise<DeepReadonly<U>>
|
||||||
: T extends Ref<infer U>
|
: T extends Ref<infer U>
|
||||||
? Ref<DeepReadonly<U>>
|
? Readonly<Ref<DeepReadonly<U>>>
|
||||||
: T extends {}
|
: T extends {}
|
||||||
? { readonly [K in keyof T]: DeepReadonly<T[K]> }
|
? { readonly [K in keyof T]: DeepReadonly<T[K]> }
|
||||||
: Readonly<T>
|
: Readonly<T>
|
||||||
|
|
|
@ -11,7 +11,8 @@ import {
|
||||||
toRefs,
|
toRefs,
|
||||||
ToRefs,
|
ToRefs,
|
||||||
shallowReactive,
|
shallowReactive,
|
||||||
watch
|
watch,
|
||||||
|
readonly
|
||||||
} from './index'
|
} from './index'
|
||||||
|
|
||||||
function plainType(arg: number | Ref<number>) {
|
function plainType(arg: number | Ref<number>) {
|
||||||
|
@ -208,6 +209,9 @@ expectType<{
|
||||||
b: Ref<number>
|
b: Ref<number>
|
||||||
}>(objRefs)
|
}>(objRefs)
|
||||||
|
|
||||||
|
// readonly() + ref()
|
||||||
|
expectType<Readonly<Ref<number>>>(readonly(ref(1)))
|
||||||
|
|
||||||
// #2687
|
// #2687
|
||||||
interface AppData {
|
interface AppData {
|
||||||
state: 'state1' | 'state2' | 'state3'
|
state: 'state1' | 'state2' | 'state3'
|
||||||
|
|
Loading…
Reference in New Issue