Skip to content
Permalink
Browse files
fix(types): calling readonly() with ref() should return Readonly<Ref<…
…T>> (#5212)
  • Loading branch information
HcySunYang committed Jan 21, 2022
1 parent 171f5e9 commit c64907d261bafd763b90e493d1bc0ad19869366f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
@@ -438,7 +438,8 @@ describe('reactivity/readonly', () => {
})

test('should make ref readonly', () => {
const n: any = readonly(ref(1))
const n = readonly(ref(1))
// @ts-expect-error
n.value = 2
expect(n.value).toBe(1)
expect(
@@ -141,7 +141,7 @@ export type DeepReadonly<T> = T extends Builtin
: T extends Promise<infer U>
? Promise<DeepReadonly<U>>
: T extends Ref<infer U>
? Ref<DeepReadonly<U>>
? Readonly<Ref<DeepReadonly<U>>>
: T extends {}
? { readonly [K in keyof T]: DeepReadonly<T[K]> }
: Readonly<T>
@@ -10,7 +10,8 @@ import {
toRef,
toRefs,
ToRefs,
shallowReactive
shallowReactive,
readonly
} from './index'

function plainType(arg: number | Ref<number>) {
@@ -236,6 +237,9 @@ expectType<Ref<string>>(p2.obj.k)
expectType<Ref<number>>(x)
}

// readonly() + ref()
expectType<Readonly<Ref<number>>>(readonly(ref(1)))

// #2687
interface AppData {
state: 'state1' | 'state2' | 'state3'

0 comments on commit c64907d

Please sign in to comment.