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

Mistyped computed getters with parameters using setup function #1139

Closed
extrem7 opened this issue Mar 11, 2022 Discussed in #1065 · 1 comment
Closed

Mistyped computed getters with parameters using setup function #1139

extrem7 opened this issue Mar 11, 2022 Discussed in #1065 · 1 comment

Comments

@extrem7
Copy link

extrem7 commented Mar 11, 2022

Discussed in #1065

Originally posted by Glandos February 15, 2022
I followed #978 using the exact same store.
I am using a Vue 2 project, in an SFC with vue-class-component (yes, this is an already started project…):

<script lang="ts">
import { Vue, Component } from 'vue-property-decorator'
import { useStoreCounter } from '@/stores/counter'


@Component
export default class UserDetails extends Vue {
  store = useStoreCounter()

  mounted() {
    this.$log.warn('Store', this.store.isEven, this.store.messageIfEven("ahah"))
  }
}
</script>

However, both Vetur in VSCode and the Typescript checker complain on the messageIfEven saying that:

(property) messageIfEven: string | undefined
Cannot invoke an object which is possibly 'undefined'.Vetur(2722)
This expression is not callable.
  Type 'String' has no call signatures.Vetur(2349)

So it seems that the getter is weirdly unwrapped, since it only retains its Result. But executing the code shows me that messageIfEven is a function.

What did I miss?


I have the same issue with computed returned by store.

const getNextDocument = computed(() => (id: number) => {
    const index = documents.findIndex((d) => d.id === id)

    return index !== -1 && index !== documents.length - 1
      ? documents[index + 1]
      : null
})
<script setup lang="ts">
const { getNextDocument } = usePassengerStore()
</script>
<template>{{ getNextDocument(1) }}</template>

error TS2721: Cannot invoke an object which is possibly 'null'.

@posva
Copy link
Member

posva commented Mar 11, 2022

No duplicates please!

@posva posva closed this as completed Mar 11, 2022
@vuejs vuejs locked and limited conversation to collaborators Mar 11, 2022
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

2 participants