Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to properly use UCarousel API with TypeScript #3053

Open
vircoding opened this issue Jan 9, 2025 · 1 comment · May be fixed by #3740
Open

How to properly use UCarousel API with TypeScript #3053

vircoding opened this issue Jan 9, 2025 · 1 comment · May be fixed by #3740
Labels
question Further information is requested

Comments

@vircoding
Copy link

vircoding commented Jan 9, 2025

Description

I just tried the example about autoplay in UCarousel, but with TypeScript.

<script setup lang="ts">
const props = defineProps<{
  images: string[];
}>();

const carousel = useTemplateRef('carouselGallery');

onMounted(() => {
  setInterval(() => {
    if (!carousel.value) return;

    if (carousel.value.page === carousel.value.pages) {
      return carousel.value.select(0);
    }

    carousel.value.next();
  }, 5000);
});
</script>

<template>
  <UCarousel
    ref="carouselGallery"
    v-slot="{ item }"
    :items="props.images"
    :ui="{
      item: 'basis-full',
      indicators: { wrapper: 'bg-black/70 w-min px-2.5 py-1.5 gap-1 left-4 rounded-xl' },
    }"
    class="overflow-hidden"
    indicators
  >
    <img :src="item" class="w-full" draggable="true" />
  </UCarousel>
</template>

And I get some TypeScript errors:

Property 'page' does not exist on type 'CreateComponentPublicInstanceWithMixins(...)
Property 'select' does not exist on type 'CreateComponentPublicInstanceWithMixins(...)
Property 'next' does not exist on type 'CreateComponentPublicInstanceWithMixins(...)

How should I correctly infer the type for UCarousel?

Nuxt v3.15.1
NuxtUI v2.20.0

@vircoding vircoding added the question Further information is requested label Jan 9, 2025
Copy link

github-actions bot commented Feb 9, 2025

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Feb 9, 2025
@dapingtai dapingtai linked a pull request Mar 30, 2025 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants