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

239
Vistas
How to extend property of ComponentPublicInstance provided by Vue 3 in a certain vue file

I want add a custom property to ComponentPublicInstance. Example, I have a Vue file. It is using Vue 3 Composition API with <script setup lang='ts'> and I declared a Function, like this:

<script setup lang='ts'>
  function close() {
    console.log("It will be closed")
  }
</script>

I redner this file by render porvided by vue, and this is part of my code:

export const Notification = function (options: Options){
  const container = document.createElement('div')
  const vnode = h(notification, {...options}) 
  // The Render contribute to make vnode processing diff and patch and then mounted on the Container
  render(vnode, container)
  const instance = vnode.component?.proxy
  addIntance(vnode.component as ComponentInternalInstance)
  console.log("vnode.component", vnode.component)
  return instance
} as NotificationProperty

There is an Array named instanceList saving the instance of Notification, and I want to call the close in the instance, and I got a error Property 'close' does not exist on type 'ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>>'.. This is my code:

Notification.closeAll = function () {
  instanceList.forEach((instance: ComponentInternalInstance, index: number) => {
    instance.proxy?.close() // There is an error.
    instanceList.splice(1, index)
  })
}

I have tried to use the methods following.

  1. using defineExpose to export close function.
  2. to declare a module in the shims-vue.d.ts
declare module "./components/notification/Notification.vue" { 
  interface ComponentCustomProperties {
    close: () => any;
  }
}

or

declare module "@vue/runtime-core" { 
  interface ComponentCustomProperties {
    close: () => any;
  }
}

Both are not working.

Now, I have no idea how to cope with the problem. Thanks for your help.

about 4 years ago · Juan Pablo Isaza
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