TS2339 when calling class method
See original GitHub issueI’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:
- Created 4 years ago
- Comments:7 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 beVue
type. Annotate the instance toany
would solve the problem.This is such a disaster, people need to move away from and vue and js in general. GOD!!!