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

TypeScript error using getter in template #44

Open
oliv3 opened this issue May 24, 2021 · 1 comment
Open

TypeScript error using getter in template #44

oliv3 opened this issue May 24, 2021 · 1 comment

Comments

@oliv3
Copy link

oliv3 commented May 24, 2021

Hi, I have this getter that returns a number:

export type Getters = {
  (...)
  getItems(state: State): number
}

and

export const getters: GetterTree<State, State> & Getters = {
  (...)
  getItems: state => state.items
}

I can use getItems.value in methods and it works fine.
But if I try to use getItems in the template, e.g. <div v-if="getItems < 2" (...)> I get this error:

(property) getItems: Ref<any>
Operator '<' cannot be applied to types 'Ref<any>' and 'number'

What's going wrong ? Thanks (and thank you for this very useful library).

@oliv3
Copy link
Author

oliv3 commented May 24, 2021

The warning/error goes away if I use the + operator, e.g. <div v-if="+getItems < 2" (...)>. Is this what should be done ?

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

1 participant