I have a Vue project in which I created a new and plain TypeScript file Validation.ts
:
import Vue from 'vue';
import BaseInput from '@/components/base/BaseInput.vue';
class ValidationService extends Vue {
validateFields(fields: BaseInput[]): boolean {
return this.$store.state.skipValidation || fields.map(field => field.validate()).every(Boolean);
}
}
export default new ValidationService();
My class BaseInput
has the public method validate()
(which I'm able to call successfully from within other Vue components).
But TypeScript now complains because it can't find the BaseInput
class. When I try to follow the import I end up in the shims-vue.d.ts
file.
How can I properly import a Vue component from outside a .vue
file?
Or is there a better solution to provide Vue with some global TypeScript methods then defining them in a plain .ts
file?