Skip to content

Commit

Permalink
Add GeolocationPositionParameters type
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed Jul 4, 2024
1 parent e43f3f5 commit 073db67
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/geolocation-position.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import type { GeolocationCoordinatesParameters } from "./geolocation-coordinates.js";
import { createCoordinates } from "./geolocation-coordinates.js";

export type GeolocationPositionParameters = {
coords: GeolocationCoordinatesParameters;
} & Pick<globalThis.GeolocationPosition, "timestamp">;

const internal = new WeakMap<
globalThis.GeolocationPosition,
{ isHighAccuracy: boolean }
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 21 additions & 0 deletions test/vitest/geolocation-position-parameters.spec.ts
Original file line number Diff line number Diff line change
@@ -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<GeolocationPositionParameters>().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
});
});

0 comments on commit 073db67

Please sign in to comment.