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.

TS2339 when calling class method

See original GitHub issue

I’m using vue-cli-service to build my vuejs application. In my Jest test, I get the component instance, but can’t call methods on that instance:

Test.vue

<template>
    <div>{{method()}}</div>
</template>

<script lang="ts">
    import { Component, Vue } from 'vue-property-decorator';

    @Component
    export default class Test extends Vue {
        public method(): string {
            return 'hello';
        }
    }
</script>

Test.spec.ts

import 'jest';
import {mount} from '@vue/test-utils';
import Test from '@/views/common/Test.vue';

describe('Test.vue', () => {
    let wrapper: any;

    beforeEach(() => {
        wrapper = mount(Test);
    });

    test('test method call', () => {
        const test = wrapper.find(Test).vm as Test;
        expect(test.method()).toEqual('hello');
    });
});

In Test.spec.ts, I get this error, both in editor and in typescript window:

Error:(14, 21) TS2339: Property ‘method’ does not exist on type ‘Vue’.

But the test is OK, so test.method() is resolved successfully at runtime.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ktsncommented, Jun 5, 2019

This is technically not related with vue-class-component. If you have vue-shim.d.ts and declare *.vue file type in it, all your Vue component from *.vue file will be Vue type. Annotate the instance to any would solve the problem.

0reactions
chaithanyaMarripaticommented, Oct 17, 2022

This is such a disaster, people need to move away from and vue and js in general. GOD!!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

vue-class-component : TS2339 when calling class method
Based on Steven's answer, I understood that shims-vue.d.ts is necessary to use component as typescript classes. But the problem is that they ...
Read more >
Classes - Angular Book
We created a Page class that has public method render . Internally render calls three separate methods to render header, content and footer...
Read more >
Page 2 - Yakov Fain
1. Declaring an abstract class 2. Declaring and implementing a method 3. “Invoking” the abstract method 4. Declaring an abstract method.
Read more >
Property 'status' does not exist on type 'Error' in TS | bobbyhadz
The error "Property 'status' does not exist on type 'Error'" occurs because the status property is not available on the Error interface. To...
Read more >
Is it possible to define method outside the class in typescript
is there any way to bypass ts 2339 in to access class methods OR is it ... then why is it not just...
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