Hi. Can somebody explain to me how to properly type ref
in Vue.js to get Typescript support?
There is IonContent
With such types:
export declare const IonContent: import("vue").DefineComponent<JSX.IonContent & import("./vue-component-lib/utils").InputProps<string | number | boolean>, object, {}, import("vue").ComputedOptions, import("vue").MethodOptions, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<JSX.IonContent & import("./vue-component-lib/utils").InputProps<string | number | boolean>>, {}>;
And we are using it like so:
<ion-content
ref="content" //ref here
:scroll-events="true"
@ionScroll="onContentScroll($event)"
class="match-page_content"
>
const content = ref(null) //TS complaints
Then I import the type, like so:
import { IonContent } from '@ionic/vue';
const content = ref<typeof IonContent | null>(null);
Now it does not complain, but it still says that $el
is any
- but I know for a fact there are those commented out methods…
const handleSlideChange = (swiper: ISwiper) => {
setTimeout(() => {
if (content.value) {
content.value.$el. // says any
// content.value.$el.scrollToTop(250); //but I know it is working
swiper.updateAutoHeight();
}
}, 100);
};
So how to properly type it, so that I will get autocomplete and support on $el.
and all further properties?