chore(ts): replace 7 \as unknown as\ shims with proper types
Most of the existing coercions are legitimate (Drizzle raw-SQL row shapes, linkedom DOMParser interop, fit-file-parser's loose \`any\` callback API) — leaving those is honest. The ones cleaned up here were shims around APIs that have real types we just hadn't wired: - **\`window.__leafletMap\`** (4 sites: MapHelpers.tsx, SessionView.tsx ×3) Added \`Window\` declaration in \`apps/planner/app/types/global.d.ts\`. Callers now use plain \`window.__leafletMap\` typed as \`L.Map | undefined\`. - **\`L.markerClusterGroup\`** (PoiPanel.tsx) — leaflet.markercluster augments the global \`L\` namespace at runtime but ships no types. Added a \`declare module \"leaflet\"\` block in the same global.d.ts with a minimal signature for what we actually use. - **\`L.DomEvent.preventDefault / .stop\`** taking a Leaflet event rather than a native one (PlannerMap.tsx, RouteInteraction.tsx, NoGoAreaLayer.tsx). Leaflet events carry the native event under \`.originalEvent\`; using that drops the cast entirely. - **\`_creds as unknown as OAuthCredentials\`** orphan in wahoo/webhook.ts — \`_creds\` was unused inside the callback (the void-cast was a no-op preserving the type for documentation). Replaced with \`async ()\`, dropped the unused import. Net: 26 \`as unknown as\` / \`as any\` sites → 19, all remaining ones gated by external lib interop or Drizzle raw-SQL. Full repo: pnpm typecheck / lint / test all green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
ec86f722d9
commit
985ec54023
8 changed files with 45 additions and 12 deletions
|
|
@ -11,7 +11,7 @@ export function MapExposer() {
|
|||
const map = useMap();
|
||||
useEffect(() => {
|
||||
if (typeof window !== "undefined") {
|
||||
(window as unknown as Record<string, unknown>).__leafletMap = map;
|
||||
window.__leafletMap = map;
|
||||
}
|
||||
}, [map]);
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ export function NoGoAreaLayer({ noGoAreas, doc, enabled, onToggle }: NoGoAreaLay
|
|||
|
||||
const polygon = L.polygon(latLngs, NO_GO_STYLE);
|
||||
polygon.on("contextmenu", (e) => {
|
||||
L.DomEvent.preventDefault(e as unknown as Event);
|
||||
L.DomEvent.preventDefault(e.originalEvent);
|
||||
suppressObserverRef.current = true;
|
||||
doc.transact(() => noGoAreas.delete(i, 1), "local");
|
||||
suppressObserverRef.current = false;
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ export function PlannerMap({ yjs, sessionId, onRouteRequest, highlightPosition,
|
|||
moveWaypoint(i, lat, lng);
|
||||
},
|
||||
contextmenu: (e) => {
|
||||
L.DomEvent.preventDefault(e as unknown as Event);
|
||||
L.DomEvent.preventDefault(e.originalEvent);
|
||||
const orig = e.originalEvent as MouseEvent;
|
||||
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
|
||||
import("leaflet.markercluster").then(() => {
|
||||
if (!mounted) return;
|
||||
// After import, L.markerClusterGroup is available
|
||||
const cluster = (L as unknown as { markerClusterGroup: (opts?: object) => L.LayerGroup }).markerClusterGroup({
|
||||
// After import, L.markerClusterGroup is available (typed via
|
||||
// module augmentation in app/types/global.d.ts).
|
||||
const cluster = L.markerClusterGroup({
|
||||
maxClusterRadius: 40,
|
||||
disableClusteringAtZoom: 15,
|
||||
showCoverageOnHover: false,
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ export function RouteInteraction({
|
|||
|
||||
// Prevent double-click zoom when clicking ghost marker
|
||||
marker.on("dblclick", (e) => {
|
||||
L.DomEvent.stop(e as unknown as Event);
|
||||
L.DomEvent.stop(e.originalEvent);
|
||||
});
|
||||
|
||||
map.on("mousemove", onMouseMove);
|
||||
|
|
|
|||
|
|
@ -195,18 +195,18 @@ export function SessionView({ sessionId, hasJournalCallback, returnUrl, initialW
|
|||
}, []);
|
||||
|
||||
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);
|
||||
}, []);
|
||||
|
||||
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] });
|
||||
setIsZoomedByChart(true);
|
||||
}, []);
|
||||
|
||||
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;
|
||||
const coordsJson = yjs.routeData.get("coordinates") as string | undefined;
|
||||
if (!coordsJson) return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue