Aweda Aweda - 1 month ago 37
TypeScript Question

TypeScript error: Property 'app' does not exist on type 'Navigator'

I keep getting this error:

> TypeScript error: Property 'app' does not exist on type 'Navigator'


while using this code:

navigator.app.exitApp();


I have the following plugins:

> <plugin name="cordova-plugin-device" spec="~1.1.2"/>
> <plugin name="cordova-plugin-console" spec="~1.0.3"/>
> <plugin name="cordova-plugin-whitelist" spec="~1.2.2"/>
> <plugin name="cordova-plugin-splashscreen" spec="~3.2.2"/>
> <plugin name="cordova-plugin-statusbar" spec="~2.1.3"/>
> <plugin name="ionic-plugin-keyboard" spec="~2.2.1"/>


What might be wrong with my code?

Answer

Just add an app property to the Navigator interface

interface Navigator {
    app: {
        exitApp: () => any; // Or whatever is the type of the exitApp function
    }
}