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

typescript custom error
typescript error type
javascript custom error
javascript error
javascript error message
error class
javascript error handling best practices
javascript nested error

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?


Just add an app property to the Navigator interface

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

TypeScript 2.2 · TypeScript, It still represents having a single property called label that is of type string . error: Object literal may only specify known properties, but 'colour' does not exist in  The property error needs to be declared using Object.defineProperty a short story about Object.defineProperty is it helps to define properties. The defineProperty methods take 3 parameters: the instance of the object, the property name, and an object with the configuration like the value or the getter and setter.


1. As any

(navigator as any).app.exitApp();

This should works.

2. declare a new interface

Check the typescript/lib/lib.dom.d.ts if you had import the dom lib.

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

Just like this answer. https://stackoverflow.com/a/40083037/9515185

Our First Interface, Try casting to desired type let event: KeyboardEvent = { preventDefault: () => { }, stopPropagation: () => { }, keyCode: 75 } as KeyboardEvent;. We can prefix the constructor parameters with the public or private keyword to automatically have TypeScript assign the parameter as a property of the class. In this example, this removes the unnecessary declaration and assignment of both firstName and lastName .


you need to have relevant typings.

1) install typings package

npm install typings --global

2) install the the relavant typing for the package, if you are not certain about the plugins typing name, you can search too.

typings search cordova-plugin-device-orientation

typings install dt~cordova-plugin-device-orientation --global --save

and you are good to go

TypeScript error: Property '' is missing in type, When compiled/transpiled through TypeScript it generates error TS2339: Property 'myclassvar' does not exist on type 'MyClass'. If the above  In TypeScript 3.8, the type-checker is stricter, and only “exempts” properties from excess property checks if that property could plausibly satisfy an index signature. const obj1 : { [ x : string ] : number } | { a : number } ; obj1 = { a : 5 , c : 'abc' } // ~ // Error!


Getting error TS2339: Property does not exist on type for a valid ES6 , import { RouteComponentProps } from '@reach/router'; interface ISignupPageProps extends RouteComponentProps { someProp: string; } class SignupPage  The "helloStyle" class name is now a property on the styles object that can be accessed like any other property on a Javascript object. CSS Modules also help with class name collisions by auto-generating unique class names for each property on the styles object.


Reach Router and TypeScript: Property 'path' does not exist on type , But they also may have other properties of their own, e.g. HttpError objects may have a statusCode property with a value like 404 or 403 or 500 . TypeScript 3.7 allows us to add // @ts-nocheck comments to the top of TypeScript files to disable semantic checks. Historically this comment was only respected in JavaScript source files in the presence of checkJs , but we’ve expanded support to TypeScript files to make migrations easier for all users.


Custom errors, extending Error, toUppercase(); // ~~~~~~~~~~~ // error: Property 'toUppercase' does not exist on type 'string'. // Did you mean 'toUpperCase  TypeScript 3.7 Beta includes some of our most highly-requested features! Let’s dive in and see what’s new, starting with the highlight feature of 3.7: Optional Chaining. Optional Chaining. TypeScript 3.7 implements one of the most highly-demanded ECMAScript features yet: optional chaining!