Merge pull request #447 from trails-cool/chore/tighten-typescript-coercions
chore(ts): replace 7 `as unknown as` shims with proper types
This commit is contained in:
commit
2fc09165da
10 changed files with 50 additions and 13 deletions
|
|
@ -142,7 +142,7 @@ function DayColoredRoute({ data, dayBreaks, highlightedDay }: { data: GeoJsonObj
|
||||||
type: "Feature",
|
type: "Feature",
|
||||||
geometry: { type: "LineString", coordinates: seg.coords },
|
geometry: { type: "LineString", coordinates: seg.coords },
|
||||||
properties: {},
|
properties: {},
|
||||||
} as unknown as GeoJsonObject;
|
} as GeoJsonObject;
|
||||||
return (
|
return (
|
||||||
<GeoJSON
|
<GeoJSON
|
||||||
key={`${i}-${highlightedDay}`}
|
key={`${i}-${highlightedDay}`}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import { fitToGpx } from "../../fit.ts";
|
||||||
import { fetchWithTimeout } from "../../../http.server.ts";
|
import { fetchWithTimeout } from "../../../http.server.ts";
|
||||||
import { isAlreadyImported, importActivity } from "../../../sync/imports.server.ts";
|
import { isAlreadyImported, importActivity } from "../../../sync/imports.server.ts";
|
||||||
import { getServiceByProviderUser, withFreshCredentials } from "../../manager.ts";
|
import { getServiceByProviderUser, withFreshCredentials } from "../../manager.ts";
|
||||||
import type { OAuthCredentials } from "../../types.ts";
|
|
||||||
import type { WebhookEvent, WebhookReceiver } from "../../registry.ts";
|
import type { WebhookEvent, WebhookReceiver } from "../../registry.ts";
|
||||||
|
|
||||||
interface WahooWebhookBody {
|
interface WahooWebhookBody {
|
||||||
|
|
@ -52,8 +51,7 @@ export const wahooWebhook: WebhookReceiver = {
|
||||||
// through withFreshCredentials so the manager has a chance to refresh
|
// through withFreshCredentials so the manager has a chance to refresh
|
||||||
// a near-expired credential before any subsequent Wahoo call this
|
// a near-expired credential before any subsequent Wahoo call this
|
||||||
// handler might make.
|
// handler might make.
|
||||||
const buffer = await withFreshCredentials(service.id, async (_creds) => {
|
const buffer = await withFreshCredentials(service.id, async () => {
|
||||||
void (_creds as unknown as OAuthCredentials);
|
|
||||||
const resp = await fetchWithTimeout(event.fileUrl!);
|
const resp = await fetchWithTimeout(event.fileUrl!);
|
||||||
if (!resp.ok) throw new Error(`Wahoo file download failed: ${resp.status}`);
|
if (!resp.ok) throw new Error(`Wahoo file download failed: ${resp.status}`);
|
||||||
return Buffer.from(await resp.arrayBuffer());
|
return Buffer.from(await resp.arrayBuffer());
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ export function MapExposer() {
|
||||||
const map = useMap();
|
const map = useMap();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (typeof window !== "undefined") {
|
if (typeof window !== "undefined") {
|
||||||
(window as unknown as Record<string, unknown>).__leafletMap = map;
|
window.__leafletMap = map;
|
||||||
}
|
}
|
||||||
}, [map]);
|
}, [map]);
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ export function NoGoAreaLayer({ noGoAreas, doc, enabled, onToggle }: NoGoAreaLay
|
||||||
|
|
||||||
const polygon = L.polygon(latLngs, NO_GO_STYLE);
|
const polygon = L.polygon(latLngs, NO_GO_STYLE);
|
||||||
polygon.on("contextmenu", (e) => {
|
polygon.on("contextmenu", (e) => {
|
||||||
L.DomEvent.preventDefault(e as unknown as Event);
|
L.DomEvent.preventDefault(e.originalEvent);
|
||||||
suppressObserverRef.current = true;
|
suppressObserverRef.current = true;
|
||||||
doc.transact(() => noGoAreas.delete(i, 1), "local");
|
doc.transact(() => noGoAreas.delete(i, 1), "local");
|
||||||
suppressObserverRef.current = false;
|
suppressObserverRef.current = false;
|
||||||
|
|
|
||||||
|
|
@ -210,7 +210,7 @@ export function PlannerMap({ yjs, sessionId, onRouteRequest, highlightPosition,
|
||||||
moveWaypoint(i, lat, lng);
|
moveWaypoint(i, lat, lng);
|
||||||
},
|
},
|
||||||
contextmenu: (e) => {
|
contextmenu: (e) => {
|
||||||
L.DomEvent.preventDefault(e as unknown as Event);
|
L.DomEvent.preventDefault(e.originalEvent);
|
||||||
const orig = e.originalEvent as MouseEvent;
|
const orig = e.originalEvent as MouseEvent;
|
||||||
setContextMenu({ x: orig.clientX, y: orig.clientY, index: i });
|
setContextMenu({ x: orig.clientX, y: orig.clientY, index: i });
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -90,8 +90,9 @@ export function PoiMarkers({ poiState, onAddWaypoint }: PoiPanelProps) {
|
||||||
// Dynamic import to avoid bundling markercluster when POIs aren't used
|
// Dynamic import to avoid bundling markercluster when POIs aren't used
|
||||||
import("leaflet.markercluster").then(() => {
|
import("leaflet.markercluster").then(() => {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
// After import, L.markerClusterGroup is available
|
// After import, L.markerClusterGroup is available (typed via
|
||||||
const cluster = (L as unknown as { markerClusterGroup: (opts?: object) => L.LayerGroup }).markerClusterGroup({
|
// module augmentation in app/types/global.d.ts).
|
||||||
|
const cluster = L.markerClusterGroup({
|
||||||
maxClusterRadius: 40,
|
maxClusterRadius: 40,
|
||||||
disableClusteringAtZoom: 15,
|
disableClusteringAtZoom: 15,
|
||||||
showCoverageOnHover: false,
|
showCoverageOnHover: false,
|
||||||
|
|
|
||||||
|
|
@ -194,7 +194,7 @@ export function RouteInteraction({
|
||||||
|
|
||||||
// Prevent double-click zoom when clicking ghost marker
|
// Prevent double-click zoom when clicking ghost marker
|
||||||
marker.on("dblclick", (e) => {
|
marker.on("dblclick", (e) => {
|
||||||
L.DomEvent.stop(e as unknown as Event);
|
L.DomEvent.stop(e.originalEvent);
|
||||||
});
|
});
|
||||||
|
|
||||||
map.on("mousemove", onMouseMove);
|
map.on("mousemove", onMouseMove);
|
||||||
|
|
|
||||||
|
|
@ -195,18 +195,18 @@ export function SessionView({ sessionId, hasJournalCallback, returnUrl, initialW
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleChartClick = useCallback((position: [number, number]) => {
|
const handleChartClick = useCallback((position: [number, number]) => {
|
||||||
const map = (window as unknown as Record<string, unknown>).__leafletMap as L.Map | undefined;
|
const map = window.__leafletMap;
|
||||||
map?.panTo(position);
|
map?.panTo(position);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleChartDragSelect = useCallback((bounds: [[number, number], [number, number]]) => {
|
const handleChartDragSelect = useCallback((bounds: [[number, number], [number, number]]) => {
|
||||||
const map = (window as unknown as Record<string, unknown>).__leafletMap as L.Map | undefined;
|
const map = window.__leafletMap;
|
||||||
map?.fitBounds(bounds, { padding: [30, 30] });
|
map?.fitBounds(bounds, { padding: [30, 30] });
|
||||||
setIsZoomedByChart(true);
|
setIsZoomedByChart(true);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleResetZoom = useCallback(() => {
|
const handleResetZoom = useCallback(() => {
|
||||||
const map = (window as unknown as Record<string, unknown>).__leafletMap as L.Map | undefined;
|
const map = window.__leafletMap;
|
||||||
if (!map || !yjs) return;
|
if (!map || !yjs) return;
|
||||||
const coordsJson = yjs.routeData.get("coordinates") as string | undefined;
|
const coordsJson = yjs.routeData.get("coordinates") as string | undefined;
|
||||||
if (!coordsJson) return;
|
if (!coordsJson) return;
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,10 @@ export function useYjs(
|
||||||
|
|
||||||
// Initialize waypoints once after first sync
|
// Initialize waypoints once after first sync
|
||||||
if (initialWaypoints?.length && !initializedWaypoints.current) {
|
if (initialWaypoints?.length && !initializedWaypoints.current) {
|
||||||
|
// y-websocket emits both "sync" and "synced" (legacy alias). We
|
||||||
|
// keep "synced" for backwards-compat with older versions; the
|
||||||
|
// typed `.on` signature in the current lib version omits it
|
||||||
|
// even though the runtime still fires it, so we coerce.
|
||||||
(provider as unknown as { on(event: string, cb: () => void): void }).on("synced", () => {
|
(provider as unknown as { on(event: string, cb: () => void): void }).on("synced", () => {
|
||||||
// Only add if the doc is empty (avoid duplicating on reconnect)
|
// Only add if the doc is empty (avoid duplicating on reconnect)
|
||||||
if (waypoints.length === 0 && !initializedWaypoints.current) {
|
if (waypoints.length === 0 && !initializedWaypoints.current) {
|
||||||
|
|
|
||||||
34
apps/planner/app/types/global.d.ts
vendored
Normal file
34
apps/planner/app/types/global.d.ts
vendored
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
// Ambient type augmentations for the planner client.
|
||||||
|
//
|
||||||
|
// Picked up by tsconfig's default `include` (every `**/*.ts(x)` inside
|
||||||
|
// the project root). Keeps the `as unknown as Record<string, unknown>`
|
||||||
|
// dance out of every site that needs to read or write a globally-
|
||||||
|
// exposed value.
|
||||||
|
|
||||||
|
import type { Map as LeafletMap, LayerGroup } from "leaflet";
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
// Exposed by MapHelpers.tsx::MapExposer for E2E tests and external
|
||||||
|
// integrations. Optional because it's only present after the map
|
||||||
|
// mounts.
|
||||||
|
interface Window {
|
||||||
|
__leafletMap?: LeafletMap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Module augmentation for leaflet.markercluster. The plugin extends
|
||||||
|
// the global `L` namespace at runtime but ships no TypeScript types,
|
||||||
|
// so without this declaration callers fall back to `as unknown as
|
||||||
|
// {...}` shims.
|
||||||
|
declare module "leaflet" {
|
||||||
|
function markerClusterGroup(options?: MarkerClusterGroupOptions): LayerGroup;
|
||||||
|
interface MarkerClusterGroupOptions {
|
||||||
|
showCoverageOnHover?: boolean;
|
||||||
|
spiderfyOnMaxZoom?: boolean;
|
||||||
|
zoomToBoundsOnClick?: boolean;
|
||||||
|
maxClusterRadius?: number;
|
||||||
|
[key: string]: unknown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export {};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue