nuxt-modules / turnstile

đŸ”Ĩ Cloudflare Turnstile integration for Nuxt
https://cloudflare.com/products/turnstile
MIT License
238 stars 17 forks source link

[ts]: Typing Template Refs #341

Open WuChenDi opened 1 month ago

WuChenDi commented 1 month ago

📚 What are you trying to do?

Hello everyone, my apologies for the interruption.

How can one determine the type of the NuxtTurnstile component in practical development?

import { NuxtTurnstile } from '#components'

// const turnstile = ref<InstanceType<typeof NuxtTurnstile> | null>()

const turnstile = useTemplateRef<typeof NuxtTurnstile>(null)

image

image

image

🔍 What have you tried?

No response

ℹī¸ Additional context

No response

Yizack commented 1 month ago

It works for me 🤔

import { NuxtTurnstile } from "#components";
const turnstile = ref<InstanceType<typeof NuxtTurnstile> | null>(null);

image

image

WuChenDi commented 1 month ago

@Yizack Thank you for your response.

As mentioned in my initial reply, I attempted to write the code in this manner; however, the result was any, which is of no use to me.

    devDependencies:
      '@nuxtjs/turnstile':
        specifier: ^0.9.7

image

Yizack commented 1 month ago

I see, have you tried re-generating the types again using npx nuxi prepare and restarting TS server I believe sometimes when reopening the project it gives any, probably not the best to do but you could always use as workaround if you need it

const turnstile = ref<{ reset: () => void }>();
WuChenDi commented 1 month ago

No, I have attempted to execute npx nuxi prepare, but regrettably, the outcome remains any.

Currently, this is how I have approached the issue.

ref<{ reset: () => void }>();