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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect behaviour when used with browser geolocation coordinates object #711

Open
dearlordylord opened this issue Mar 8, 2024 · 0 comments

Comments

@dearlordylord
Copy link

馃悰 Bug report

Current Behavior

When you parse the result of navigator.geolocation.getCurrentPosition, despite coords object having field values, a codec parsing these values returns them successfully unassigned, e.g. an empty object, even when the values are required

Expected behavior

for codec

const geoCoordinatesCodec = t.type({
  latitude: t.number,
  longitude: t.number,
});

and


navigator.geolocation.getCurrentPosition((position) => {

  const result = geoCoordinatesCodec.decode(position.coords);

});

result has to be {right: {latitude: ..., longitude: ...}}

instead, the result is {right: {}}

Reproducible example

https://github.com/Firfi/io-ts-geo-repro

Suggested solution(s)

I expect io-ts either return parse errors or correct value

Additional context

It seems to be some special object proxying / getters involved in location.coords object

if I do

 const result = geoCoordinatesCodec.decode({
  latitude: position.coords.latitude,
  longitude: position.coords.longitude
});

it works as expected

Your environment

macos + chrome,

osx + safari

https://github.com/Firfi/io-ts-geo-repro - latest

Software Version(s)
io-ts 2.2.21
fp-ts 2.16.2
TypeScript 5.3.2
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

1 participant