From 6b6724f3de44ce6a2159ec7bf9302c517006eeb6 Mon Sep 17 00:00:00 2001 From: gnezim Date: Mon, 20 Apr 2026 08:28:57 +0300 Subject: [PATCH] Drop 10 non-null assertions from MapCanvas zoom-layer loops MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace `zoomLayers[c]![t]!` patterns with explicit null-guard `continue` branches. The dimensions (2×5) are still initialized the same way; the narrowing just makes the linter happy without changing runtime behavior. Warning count: 65 → 55. --- .../flights-map/components/MapCanvas.tsx | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/features/flights-map/components/MapCanvas.tsx b/src/features/flights-map/components/MapCanvas.tsx index 33ae9617..5af0e4ec 100644 --- a/src/features/flights-map/components/MapCanvas.tsx +++ b/src/features/flights-map/components/MapCanvas.tsx @@ -211,9 +211,12 @@ export const MapCanvas: FC = ({ for (let c = 0; c < 2; c++) { const countryType = c === 0 ? "ru" : "other"; + const tierLayers = zoomLayers[c]; + if (!tierLayers) continue; for (let t = 0; t < 5; t++) { const tier = t + 2; - const layer = zoomLayers[c]![t]!; + const layer = tierLayers[t]; + if (!layer) continue; const inRange = tier <= currentZoom; const hiddenByIntl = intl && countryType === "ru"; const hiddenByDom = dom && countryType === "other"; @@ -276,9 +279,10 @@ export const MapCanvas: FC = ({ const segments: L.LatLng[] = []; for (let i = 0; i < resolved.length - 1; i++) { - const from = resolved[i]!.getLatLng(); - const to = resolved[i + 1]!.getLatLng(); - const arc = buildGreatCircleArc(from, to); + const src = resolved[i]; + const dst = resolved[i + 1]; + if (!src || !dst) continue; + const arc = buildGreatCircleArc(src.getLatLng(), dst.getLatLng()); segments.push(...(i === 0 ? arc : arc.slice(1))); } @@ -318,8 +322,10 @@ export const MapCanvas: FC = ({ // zoom + toggles. const zoomLayers: L.LayerGroup[][] = [[], []]; for (let c = 0; c < 2; c++) { + const tierLayers = zoomLayers[c]; + if (!tierLayers) continue; for (let t = 0; t < 5; t++) { - zoomLayers[c]![t] = L.layerGroup(); + tierLayers[t] = L.layerGroup(); } } zoomLayersRef.current = zoomLayers; @@ -358,9 +364,9 @@ export const MapCanvas: FC = ({ // Clear everything before re-adding. flatLayer.clearLayers(); highlightLayer.clearLayers(); - for (let c = 0; c < 2; c++) { - for (let t = 0; t < 5; t++) { - zoomLayers[c]![t]!.clearLayers(); + for (const tierLayers of zoomLayers) { + for (const layer of tierLayers) { + layer.clearLayers(); } } markerIndexRef.current = new Map(); @@ -395,10 +401,11 @@ export const MapCanvas: FC = ({ marker.addTo(highlightLayer); } else if (isCategorized) { const countryIdx = m.countryType === "ru" ? 0 : 1; - const rawTier = m.zoomLevel!; + const rawTier = m.zoomLevel ?? 6; const tier = rawTier >= 2 && rawTier <= 6 ? rawTier : 6; const tierIdx = tier - 2; - marker.addTo(zoomLayers[countryIdx]![tierIdx]!); + const target = zoomLayers[countryIdx]?.[tierIdx]; + if (target) marker.addTo(target); } else { marker.addTo(flatLayer); }