turnstile icon indicating copy to clipboard operation
turnstile copied to clipboard

[ts]: Typing Template Refs

Open WuChenDi opened this issue 1 year ago â€ĸ 4 comments

📚 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

WuChenDi avatar Sep 23 '24 09:09 WuChenDi

It works for me 🤔

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

image

image

Yizack avatar Sep 23 '24 10:09 Yizack

@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

WuChenDi avatar Sep 23 '24 10:09 WuChenDi

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 }>();

Yizack avatar Sep 23 '24 10:09 Yizack

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 }>();

WuChenDi avatar Sep 23 '24 10:09 WuChenDi