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

bug: computed properties expect to be invoked #232

Open
anthony9187 opened this issue Dec 2, 2024 · 2 comments
Open

bug: computed properties expect to be invoked #232

anthony9187 opened this issue Dec 2, 2024 · 2 comments

Comments

@anthony9187
Copy link

According to the documentation (and functionally in practice), computed properties should be accessed as similarly to a getter when used outside of the template:

this.computedProperty.value

however typescript throws an error:

Property 'value' does not exist on type '() =>...

which looks like it's expecting computedProperty to be invoked:

this.computedProperty().value

it's more of an annoying type issue than anything else, everything seems to function as expected

@michielvandergeest
Copy link
Collaborator

hello @anthony9187, computed props can be accessed outside the template scope by referring to them simply as this.mycomputedProperty. There is no .value-suffix involved there, so Typescript is correctly telling you that Property 'value' does not exists ...

There is also no need to invoke the computed property. The idea is that whenever you access the property (i.e. this.mycomputedProperty) the function associated with the property is executed, allowing you to dynamically generate the response value.

I've tried to search the docs, to see if it's documented wrongly somewhere, but couldn't find it. I may have missed something, so if you wouldn't mind please let us know where this was documented incorrectly (or confusing).

@anthony9187
Copy link
Author

anthony9187 commented Dec 11, 2024

Hey @michielvandergeest, sorry if my example was unclear - .value was just an example. In this screenshot we can see what I mean:

Screenshot 2024-12-11 at 4 27 39 PM

I have a computed property getStyles that returns an object which has a property gutterX. If I attempt to reference the computed property as you've described, I'm met with the above error which incorrectly tells me I need to invoke the method.

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

No branches or pull requests

2 participants