Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

248
Vistas
How to define typed route props using an interface?

I created a new project via npm init vue@latest and know that I can define component props with the new syntax ( taken from the docs ) like so

<script setup lang="ts">
const props = defineProps<{
  foo: MyRequiredType
  bar?: MyOptionalType
}>()
</script>

Now I have to define route props and would like to know if I must use the following syntax or if there is a way to use the syntax from above?

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      component: MyView,
      props: {
        foo: {
          type: Object as PropType<MyRequiredType>,
          required: true
        },
        bar: {
          type: Object as PropType<MyOptionalType>,
          required: false,
          default: undefined,
        },
      },
    },
  ],
});

I tried to use the syntax from above but get the warning

[Vue warn]: defineProps() is a compiler-hint helper that is only usable inside of a single file component. Its arguments should be compiled away and passing it at runtime has no effect.

about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda