We want to access the user's location using the Geolocation API.
This snippet works fine:
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition((position: GeolocationPosition) => console.log(position));
}
VSCode also doesn't show any errors or warnings, but the Angular CLI throws this error:
Cannot find name 'GeolocationPosition'.
navigator.geolocation.getCurrentPosition((position: GeolocationPosition) => console.log(position));
The project is using the following things:
- Angular 11.0.6
- tslib 2.0.0
- ts-node 8.3.0
- tslint 6.1.0
- typescript 4.0.2
Also strict type checking is enabled in Angular CLI
How to use this type and other types from that API correctly?
Running TypeScript in v4.0.x brings up
Positionas the typename, but that appears to have been renamed toGeolocationPositionin 4.1.x. Can't find any docs on why they did that. See: https://stackoverflow.com/a/66005573/510048.Recommend updating to the latest version of Typescript (currently 4.2.3)