I am trying to access the NetworkInformation interface by using a simple TypeScript function like the one shown below:
private checkNetworkConnection(): void {
const connection = Navigator.connection
|| navigator.mozConnection
|| navigator.webkitConnection;
const type = connection.type;
console.log('CONNECTION TYPE: %o', type);
console.log('DOWNLINK: %o', connection.downlink);
}
However, I keep encountering the error message connection is undefined
. After browsing on SO, I discovered that Cordova users extend the type definitions of Typescript by importing
@types/cordova-plugin-network-information
, but this doesn't resolve my issue.
You can view a working example on StackBlitz here.