Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(readonly): align behavior with vue-next. (#765)
  • Loading branch information
ygj6 committed Jul 16, 2021
1 parent ebb7975 commit 42104aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/reactivity/readonly.ts
Expand Up @@ -44,6 +44,9 @@ type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRef<T>
export function readonly<T extends object>(
target: T
): DeepReadonly<UnwrapNestedRefs<T>> {
if (__DEV__ && !isObject(target)) {
warn(`value cannot be made reactive: ${String(target)}`)
}
return target as any
}

Expand Down
4 changes: 4 additions & 0 deletions test/v3/reactivity/readonly.spec.ts
Expand Up @@ -6,6 +6,7 @@ import {
reactive,
watch,
nextTick,
readonly,
} from '../../../src'

const Vue = require('vue/dist/vue.common.js')
Expand Down Expand Up @@ -386,6 +387,9 @@ describe('reactivity/readonly', () => {
// @ts-ignore
shallowReadonly(25)
expect(`value cannot be made reactive: 25`).toHaveBeenWarned()
// @ts-ignore
readonly(25)
expect(`value cannot be made reactive: 25`).toHaveBeenWarned()
})

// #669
Expand Down

0 comments on commit 42104aa

Please sign in to comment.