Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geolocation.watchPosition() example snippet doesn't compile #741

Closed
yzhan94 opened this issue Oct 25, 2016 · 9 comments
Closed

Geolocation.watchPosition() example snippet doesn't compile #741

yzhan94 opened this issue Oct 25, 2016 · 9 comments

Comments

@yzhan94
Copy link

yzhan94 commented Oct 25, 2016

Geolocation.watchPosition() example code doesn't compile; running npm run build throws the following errors:

[12:47:46]  Property 'code' does not exist on type 'Geoposition | PositionError'. 
[12:47:46]  Property 'coords' does not exist on type 'Geoposition | PositionError'. 
[12:47:46]  Property 'coords' does not exist on type 'Geoposition | PositionError'. 
[12:47:46]  ngc failed 

I'm using the latest ionic-app-scripts (v 0.0.36).
It can be reproduced using the snippet given in the docs

var subscription = Geolocation.watchPosition()
                              .filter((p) => p.code === undefined) //Filter Out Errors
                              .subscribe(position => {
  console.log(position.coords.longitude + ' ' + position.coords.latitude);
});

A working solution I tried is changing the return type of the watchPosition method from the Union Type Observable<Geoposition | PositionError> to the Intersection Type Observable<Geoposition & PositionError>.

According to the official documentation, in a Union Type, you can only access members that are common to all types in the union; whereas an Intersection Type object will have all the members of all types.

@ihadeed
Copy link
Collaborator

ihadeed commented Oct 27, 2016

thanks

@nalkon
Copy link

nalkon commented Nov 13, 2016

I'm having the same problem. How do I get the fix?

Tnx.

@dnmd
Copy link

dnmd commented Jan 13, 2017

While using the latest ionic-native "ionic-native": "^2.2.16", the issue still remains, it's not possible to compile the example snippet. From the logs:

__WEBPACK_IMPORTED_MODULE_0_ionic_native__.a.watchPosition(...).filter is not a function

So I still remove the filter to get it compiled.

@raae
Copy link

raae commented Jan 17, 2017

@dnmd i got the same with 2.2.16, but works with 2.2.15

@ihadeed
Copy link
Collaborator

ihadeed commented Jan 18, 2017

@raae 2.2.16 is the same as 2.2.15 except it has a major fix that is not related to this plugin. You should be using 2.2.16 as 2.2.15 is broken.

@ihadeed
Copy link
Collaborator

ihadeed commented Jan 18, 2017

@dnmd are you importing rxjs/add/operator/filter ?

@raae
Copy link

raae commented Jan 19, 2017

Ok @ihadeed it now works with 2.2.16, it must have been something else then.

@badpenguin
Copy link

I'm getting this problem after upgrading ionic-angular from 2.1.0 to 2.2.0

https://forum.ionicframework.com/t/type-observable-geoposition-is-not-assignable-to-type-observable-geoposition-after-upgrading-to-2-2-0/82314

@ihadeed
Copy link
Collaborator

ihadeed commented Mar 9, 2017

@badpenguin thanks, this is because of the Rxjs version. Will push a hotfix soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants