Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

276
Views
Problemas con la etiqueta <script setup> de Vue 3.2 y los tipos de TypeScript

Estoy tratando de usar la etiqueta Vue 3.2 <script setup> con TypeScript.

Tengo un caso de uso simple en el que quiero mostrar una ID de usuario en la plantilla.

Mi código está técnicamente funcionando. Muestra la ID de usuario muy bien.

Pero hay dos cosas raras...

  1. He definido una propiedad de user con un tipo de User que importé del SDK de Firebase. Esto funciona, pero aparece un error en el tipo de User que dice: 'User' only refers to a type, but is being used as a value here. ts(2693) . ¿Por qué recibo este error y cómo solucionarlo?

  2. Los documentos de ayuda dicen que no necesito import { defineProps } from "vue"; . Pero si no realizo la importación, obtengo un 'defineProps' is not defined . Esto es confuso. ¿Por qué me veo obligado a importarlo cuando los documentos dicen lo contrario?

Aquí está mi código completo:

 <template> <div>Logged in as {{ user.uid }}</div> </template> <script setup lang="ts"> import { defineProps } from "vue"; //Docs say this is not needed, but it throws an error without it import { User } from "firebase/auth"; defineProps({ user: { type: User, //ERROR: 'User' only refers to a type, but is being used as a value here. ts(2693) required: true, }, }); </script>
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

en script setup , puede definir accesorios como este en su lugar:

 <template> <div>Logged in as {{ user.uid }}</div> </template> <script setup lang="ts"> import { defineProps } from "vue"; //Docs say this is not needed, but it throws an error without it import { User } from "firebase/auth"; defineProps<{ user: User }>(); </script>

otra solución es como sugirió @bassxzero, puede usar

 defineProps<{ user: { type: Object as PropType<User>; required: true } }>()

sin usar withDefaults , se requerirá automáticamente

también, sobre:

 import { defineProps } from "vue"; //Docs say this is not needed, but it throws an error without it

en realidad no necesita importarlo, pero debe definirlo dentro .eslitrc.js

 globals: { defineProps: 'readonly', defineEmits: 'readonly', defineExpose: 'readonly', withDefaults: 'readonly' }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!