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

private properties are not found and throw errors in the View #997

Closed
ghiscoding opened this issue Mar 1, 2022 · 8 comments
Closed

private properties are not found and throw errors in the View #997

ghiscoding opened this issue Mar 1, 2022 · 8 comments
Labels
wontfix This will not be worked on

Comments

@ghiscoding
Copy link
Contributor

This issue is related to other issues #2 and #957 and as per a comment posted here it was suggested that I open a new issue.

The team project I'm working on also has a ton of a public/private properties and I get so many errors in the View even though the code is working fine. I know that I can remove private and then everything is fine but my team won't be happy with this change and it's not very code friendly to work with so many invalid errors like those

image

@johnsoncodehk
Copy link
Member

Sorry to tell you that it should not possible, if it is protected keyword may be possible to support, but for private property I have no way to access it out side component define.

@johnsoncodehk
Copy link
Member

I just thought if I can ignore all TS2341 errors in template to bypass the problem.

@johnsoncodehk johnsoncodehk reopened this Jul 8, 2022
@panjiangyi
Copy link

panjiangyi commented Jul 8, 2022

please don't throw error when using private property in one component's own template.
it make private and public meaningless in SFC

@ghiscoding
Copy link
Contributor Author

on my side we decided to go with Vue 3 Composition API since the Vue Class Component is no longer recommended neither supported. Basically, So I don't really need this one to be fixed anymore, unless someone else requires it. Thanks for the great extension :)

@panjiangyi
Copy link

on my side we decided to go with Vue 3 Composition API since the Vue Class Component is no longer recommended neither supported. Basically, So I don't really need this one to be fixed anymore, unless someone else requires it. Thanks for the great extension :)

I decided to stick to class-style vue forever or quit vue.😆 We already have a functional programming tool like React, I think Vue should be the OOP counterpart. It’s real convenient to map states of vanilla classes to DOM through Vue.

@sawmurai
Copy link

I was wondering if you could change the generated code which is passed to typescript like so:

Instead of doing __VLS_ctx.member (which raises the error because its accessing a private member) you do __VLS_ctx['member']. At least according to the TypeScript playground that should work: https://www.typescriptlang.org/play?#code/MYGwhgzhAEDKCmwBO8Au0DeAoL0-QAckBLANzFXkJNIFl4BbaAXmgCIBGDtrAXx2AB7AHYR0xUelbD4AdziIUqABQBKANwCREQSHgA6EIIDmyiWIDaAciJl6DKwF0NQA

@johnsoncodehk
Copy link
Member

@sawmurai this is planed to resolve in v1.1.

@daniel-gomez-mck
Copy link

daniel-gomez-mck commented Nov 24, 2022

Just thinking out loud... is it really needed/desirable that a private prop/method could be accessed from template?. I understand that in this world of frontend frameworks, where every code architecture is kind of elastic, the concepts of private, protected and public may depend on the use case they are being used. So trying to keep close to OOP and its encapsulation principle, my 2 cents goes to:

  • private: visible/executable only inside the component's controller and not its template
  • protected: visible also in component's template, extending classes and its templates (the template is somehow a class that extends the controller)
  • public: accesible everywhere.

this way we could also prevent bad usages of component apis through refs.

afaik, this is the way angular language service works since v14 (I know this fact may not be a reference, but I think it worth to comment as angular shares a lot of "declarative principles" with Vue [class components] in terms of "how to code things".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

5 participants