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

163
Vistas
JavaScript to TypeScript type/interface mapping

I'm using this library in a TypeScript project. And this is how my class looks like:

import OnvifManager from 'onvif-nvt'
Class OnvifApi {
// device: any = undefined
device = {} as OnvifDevice
constructor (...params) {
// definition
}
connect (): Promise<any> {
  OnvifManager.connect(...params).then((response: OnvifDevice) => {
    this.device = response
    resolve(response)
  }
}
coreService(): Promise<Type[]> {
  this.device.add('core')
}
}

And this this interface I created for the response from onvif-nvt

interface OnvifDevice {
  address: string
  // type
  // type
  // type
  add(name: string): void
}

This class is always giving an error in coreService saying that

this.device.add is not a function.

EDIT: This is the return of the connect method, which returns the whole Camera object.

Things are working when device is defined to any.

How can I do this interface mapping from JavaScript to TypeScript?

Response from connect

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The reason is, in the interface, OnvifDevice, add is a mandatory parameter, but the device object is initialised with an empty object.

The dynamic mapping at this.device = response is not happening. Also please check if the response has add method or not while you debug.

These are the two possible symptoms I see.

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