Skip to content

Build your personal knowledge base with Trilium Notes

fix(geomap): type the shape specs strictly

Claude87f3c3b5a03e
diff --git a/apps/client/src/widgets/collections/geomap/DrawShape.spec.tsx b/apps/client/src/widgets/collections/geomap/DrawShape.spec.tsx
index 1e6ed634fb..511dae8ed4 100644
--- a/apps/client/src/widgets/collections/geomap/DrawShape.spec.tsx
+++ b/apps/client/src/widgets/collections/geomap/DrawShape.spec.tsx
@@ -5,10 +5,11 @@
*/
import { render } from "preact";
import { act } from "preact/test-utils";
-import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { afterEach, beforeEach, describe, expect, it, type Mock, vi } from "vitest";
import DrawShape, { type DrawTool, shapeFromFeature } from "./DrawShape";
import { MapStyleLoaded, ParentMap } from "./map";
+import type { GeoShape } from "./shapes";
vi.mock("terra-draw", () => {
/** Terra Draw as this component uses it: events, a snapshot, and a lifecycle. */
@@ -80,7 +81,7 @@ const CIRCLE_FEATURE = {
describe("DrawShape", () => {
let container: HTMLElement;
- let onFinish: ReturnType<typeof vi.fn>;
+ let onFinish: Mock<(shape: GeoShape) => void>;
beforeEach(() => {
instances().length = 0;
diff --git a/apps/client/src/widgets/collections/geomap/shapes.spec.ts b/apps/client/src/widgets/collections/geomap/shapes.spec.ts
index 676110273e..4de593f785 100644
--- a/apps/client/src/widgets/collections/geomap/shapes.spec.ts
+++ b/apps/client/src/widgets/collections/geomap/shapes.spec.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
-import { circleRing, closeRing, parseGeoShape, polygonFromRing, ringCenter, serializeGeoShape } from "./shapes";
+import { circleRing, closeRing, type GeoShape, parseGeoShape, polygonFromRing, ringCenter, serializeGeoShape } from "./shapes";
describe("serializeGeoShape", () => {
it("writes lat,lng pairs behind the kind's prefix, rounded but not padded", () => {
@@ -36,7 +36,7 @@ describe("serializeGeoShape", () => {
expect(parseGeoShape(serializeGeoShape({ type, coordinates }))).toEqual({ type, coordinates });
}
- const circle = { type: "circle", center: [ 13.404954, 52.520008 ], radiusMeters: 500 } as const;
+ const circle: GeoShape = { type: "circle", center: [ 13.404954, 52.520008 ], radiusMeters: 500 };
expect(parseGeoShape(serializeGeoShape(circle))).toEqual(circle);
});
});
@@ -53,7 +53,7 @@ describe("parseGeoShape", () => {
});
it("tolerates surrounding and repeated whitespace", () => {
- expect(parseGeoShape("line: 1,2 3,4 ")?.coordinates).toEqual([ [ 2, 1 ], [ 4, 3 ] ]);
+ expect(parseGeoShape("line: 1,2 3,4 ")).toEqual({ type: "line", coordinates: [ [ 2, 1 ], [ 4, 3 ] ] });
});
it("refuses what is not a shape", () => {