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

Detect incorrect ref usage in template #1840

Closed
stefnotch opened this issue Aug 12, 2020 · 2 comments
Closed

Detect incorrect ref usage in template #1840

stefnotch opened this issue Aug 12, 2020 · 2 comments

Comments

@stefnotch
Copy link

What problem does this feature solve?

Since #1682 , refs in templates are not deeply unwrapped anymore. However, always remembering that isn't easy.

I frequently type something like

{{element.scope.name}}

when I actually mean

{{element.scope.value?.name}}

Sadly, neither my IDE (Visual Studio Code with Vetur) nor Vue.js catch this issue. At runtime, you simply see nothing. It would be great if that were improved.

What does the proposed API look like?

Maybe the template compiler has enough information to catch such incorrect usage. Otherwise, I guess this is an issue for Vetur?

@posva
Copy link
Member

posva commented Aug 12, 2020

Can you provide more context like about when this is biting you?

@yyx990803
Copy link
Member

yyx990803 commented Aug 12, 2020

You can avoid exposing raw refs to the template (i.e retain the old behavior) by wrapping your element property with reactive:

return {
-  element
+  element: reactive(element)
}

It is technically possible to detect such cases in the compiler, but it is something better done at the tooling level (i.e. Vetur) since it involves type checking.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants