From 073db6740cbb85feb06421daef2d54f7650b039a Mon Sep 17 00:00:00 2001 From: Erin Millard Date: Fri, 5 Jul 2024 09:52:41 +1000 Subject: [PATCH] Add GeolocationPositionParameters type --- src/geolocation-position.ts | 4 ++++ src/index.ts | 1 + .../geolocation-position-parameters.spec.ts | 21 +++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 test/vitest/geolocation-position-parameters.spec.ts diff --git a/src/geolocation-position.ts b/src/geolocation-position.ts index 290bec3..9ca4581 100644 --- a/src/geolocation-position.ts +++ b/src/geolocation-position.ts @@ -1,6 +1,10 @@ import type { GeolocationCoordinatesParameters } from "./geolocation-coordinates.js"; import { createCoordinates } from "./geolocation-coordinates.js"; +export type GeolocationPositionParameters = { + coords: GeolocationCoordinatesParameters; +} & Pick; + const internal = new WeakMap< globalThis.GeolocationPosition, { isHighAccuracy: boolean } diff --git a/src/index.ts b/src/index.ts index f694be1..cdd37c1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,6 +13,7 @@ export { export type { GeolocationCoordinatesParameters } from "./geolocation-coordinates.js"; export * from "./geolocation-position-error.js"; export { GeolocationPosition, createPosition } from "./geolocation-position.js"; +export type { GeolocationPositionParameters } from "./geolocation-position.js"; export { Geolocation, createGeolocation } from "./geolocation.js"; export { createLocationServices } from "./location-services.js"; export type { diff --git a/test/vitest/geolocation-position-parameters.spec.ts b/test/vitest/geolocation-position-parameters.spec.ts new file mode 100644 index 0000000..d6ef0c4 --- /dev/null +++ b/test/vitest/geolocation-position-parameters.spec.ts @@ -0,0 +1,21 @@ +/* eslint-disable @typescript-eslint/no-unsafe-argument */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import type { GeolocationPositionParameters } from "fake-geolocation"; +import { describe, expectTypeOf, it } from "vitest"; + +describe("GeolocationPositionParameters", () => { + it("accepts the same properties as GeolocationPosition", () => { + expectTypeOf().toEqualTypeOf<{ + coords: { + latitude: number; + longitude: number; + altitude: number | null; + accuracy: number; + altitudeAccuracy: number | null; + heading: number | null; + speed: number | null; + }; + timestamp: number; + }>(undefined as any); // weird that this is necessary + }); +});