I have a single file component that I made called BusinessDetails. I'm using this component in another component, and I've attached the ref attribute to it to access its properties and methods. If I don't give the ref a type, I get an error when accessing its methods that says "Object is possibly null". I tried setting the type as BusinessComponent, typeof BusinessComponent, Vue.extend(BusinessComponent), and so on, but they all throw different errors. I eventually settled on just setting the type to any, and living with the eslint warnings. While this goes around the problem, is there was an appropriate way to do this?
<q-layout view="hHh LpR lfr">
<q-header>
<q-toolbar>
<q-btn flat round @click="$router.go(-1)" icon="arrow_back" aria-label="Back"/>
<q-toolbar-title>Create Account</q-toolbar-title>
</q-toolbar>
</q-header>
<q-page-container>
<q-page>
<business-details ref="businessDetails" />
</q-page>
</q-page-container>
</q-layout>
export default Vue.extend({
name: "CreateAccount",
components: {
BusinessDetails
},
setup () {
const businessDetails: Ref<any> = ref(null);
const isCurrentPageValid = (page: number): Promise<boolean> => {
switch (page) {
case AccountGroup.BUSINESS:
return businessDetails.value.isValid();
default:
return Promise.resolve(true);
}
};
return {
businessDetails,
isCurrentPageValid
};
}
});