Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

210
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda