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

feat: add type-level readonly() api #593

Merged
merged 3 commits into from
Dec 7, 2020
Merged

Conversation

antfu
Copy link
Member

@antfu antfu commented Nov 22, 2020

No description provided.

* Creates a readonly copy of the original object. Note the returned copy is not
* made reactive, but `readonly` can be called on an already reactive object.
*/
export function readonly<T extends object>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if is worth to have readonly if it's the same as shallowReadonly

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's for the API alignment with Vue 3, lowing the difference between them. Thinking import { readonly } from 'vue-demi will work for Vue 3 but failed on Vue 2. This implementation acts like a noop but providing the type-level checking as the same as Vue 3. Should be good enough for users using TypeScript.

src/reactivity/readonly.ts Outdated Show resolved Hide resolved
@antfu antfu requested a review from pikax December 3, 2020 02:41
@antfu antfu merged commit 3b726d4 into vuejs:master Dec 7, 2020
@antfu antfu deleted the feat/readonly branch December 7, 2020 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants