Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

213
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!