question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Vue + Typescript] Property does not exist on type in computed function

See original GitHub issue

Version

2.5.17

Reproduction link

https://codesandbox.io/s/10l5yrl9rq

Steps to reproduce

Codesandbox seems not support typescript code intelligense in *.vue, the file is src/index.vue

Here is the code:

<script lang="ts">
import Vue from 'vue'

interface TestInterface {
  a: string
}

export default Vue.extend({
  props: {
    prop1: {
      type: Object as () => TestInterface,
    },
  },
  computed: {
    computed1() {
      return this.prop1.a
    }
  }
})
</script>

What is expected?

Typescript compiler will not complaint

What is actually happening?

Property ‘prop1’ does not exist on type ‘{ computed1(): any; }’.

Is there any way to solve this problem?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:19 (2 by maintainers)

github_iconTop GitHub Comments

55reactions
stayacidcommented, Feb 10, 2021

Let me left a note for everyone who’re confused as i am: annotate ALL return types of computed properties.

55reactions
ktsncommented, Aug 9, 2018

Please read https://vuejs.org/v2/guide/typescript.html You should do the following things to make type inference works.

  • set strict: true or noImplicitThis: true for compiler option.
  • annotate return type of computed properties.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolve "Property does not exist on type 'Vue'" error
Show activity on this post. Here is an example of class based component: import { Component, Vue, Watch } from 'vue-property-decorator' @ ...
Read more >
Typescript: Property 'foo' does not exist on type 'Vue' - Sami C.
When I added a type on my setter val the error was no longer present! set(val: boolean) { (this as any).$emit('input', false); },....
Read more >
Property '$wait' does not exist on type 'Create Component ...
I am learning TypeScript and I am getting an error I don't really know how to handle it. TS2339: Property '$wait' does not...
Read more >
‍♂️ ‍♀️ Vue 3 error with using TypeScript: property X does ...
‍♂️ ‍♀️ Vue 3 error with using TypeScript: property X does not exist on type 'EventTarget' · Simple Errors (3 Part Series) ·...
Read more >
Property does not exist on type data - Ionic Vue
ts to a property. I successfully get the results, however, when I import the function and I try to pass the values to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found