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

212
Vistas
type script android interface

So I am developing for a couple a devices and basically need to do a check to determine the device. For example

// Android being js interface
if(Android) return setupAndroid()
else if(exampleDevice) return method()
etc

If you have done this before you know my problem. If you open this app in a browser not on android it will crash because android does not exist. I have to do it this way and since ive started I do not want to stop till I figure out a way to handle this. I have tried creating a ts interface and did not work. I need a way to say this Android interface does exist only in the android layer. So this type of check is going to happen for every device. The number of devices does not matter. What matters is how do you avoid errors of non existing variables.

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

0

I'm guessing you're exposing a specific Android interface via WebView.addJavascriptInterface, but as far as TypeScript is concerned you should declare the global variable as if it always exists. If you want to be extra safe, mark it as possibly undefined so you always have to check its existence before use.

interface AndroidType {
  field1: string;
  method1(): void;
}
declare var Android: AndroidType | undefined;

if (Android) {
  Android.field1 = "foo";
  Android.method1();
}

Playground Link

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