Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(readonly): align behavior with vue-next. #765

Merged
merged 2 commits into from Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/reactivity/readonly.ts
Expand Up @@ -44,6 +44,11 @@ type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRef<T>
export function readonly<T extends object>(
target: T
): DeepReadonly<UnwrapNestedRefs<T>> {
if (!isObject(target)) {
if (__DEV__) {
ygj6 marked this conversation as resolved.
Show resolved Hide resolved
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