Drop 11 more non-null assertions across 5 files

- ErrorPage.tsx: FALLBACK_CONFIG literal instead of ERROR_CONFIG["500"]!
- ErrorBoundary.tsx: hoist FALLBACK_RU / FALLBACK_EN to consts so
  pickStrings returns them without the bang.
- routesToPolylines.ts: narrow spider-mode block on filterState.departure
  truthy; guard each route-code lookup.
- FlightsMapStartPage.tsx: narrow firstRoute/depCode/arrCode together
  instead of asserting each individually.
- OnlineBoardDetailsPage.tsx: IIFE over legs[i+1] for TransferBar;
  `_canonicalOrigin` prefix for currently-unused prop.

Warning count: 30 → 19.
This commit is contained in:
2026-04-20 09:22:49 +03:00
parent 298f007463
commit 8d409572b7
5 changed files with 34 additions and 17 deletions
@@ -238,9 +238,10 @@ export const FlightsMapStartPage: FC<FlightsMapStartPageProps> = ({
if (!filterState.departure || !filterState.arrival) return [];
if (filteredRoutes.length === 0) return [];
const first = filteredRoutes[0]!.route;
const depCode = first[0]!;
const arrCode = first[first.length - 1]!;
const firstRoute = filteredRoutes[0]?.route;
const depCode = firstRoute?.[0];
const arrCode = firstRoute?.[firstRoute.length - 1];
if (!firstRoute || !depCode || !arrCode) return [];
const depCityCode = getCityCodeByAirportCode(dictionaries, depCode) ?? depCode;
const arrCityCode = getCityCodeByAirportCode(dictionaries, arrCode) ?? arrCode;
@@ -38,12 +38,13 @@ export function routesToPolylines(
const hasArrival = Boolean(filterState.arrival);
const isSpiderMode = hasDeparture && !hasArrival;
if (isSpiderMode) {
const fromCode = toCity(filterState.departure!);
if (isSpiderMode && filterState.departure) {
const fromCode = toCity(filterState.departure);
const destCodes = new Set<string>();
for (const r of routes) {
if (r.route.length > 1) {
const dest = toCity(r.route[r.route.length - 1]!);
const last = r.route[r.route.length - 1];
if (r.route.length > 1 && last) {
const dest = toCity(last);
if (dest !== fromCode) destCodes.add(dest);
}
}
@@ -74,7 +75,10 @@ export function intermediateCityIds(
const ids = new Set<string>();
for (const r of routes) {
if (r.route.length <= 2) continue;
for (let i = 1; i < r.route.length - 1; i++) ids.add(toCity(r.route[i]!));
for (let i = 1; i < r.route.length - 1; i++) {
const code = r.route[i];
if (code) ids.add(toCity(code));
}
}
return [...ids];
}
@@ -339,9 +339,11 @@ function FlightLegs({
<FlightDetailsAccordion leg={leg} viewType="Onlineboard" />
</div>
{i < legs.length - 1 && (
<TransferBar leg={leg} nextLeg={legs[i + 1]!} viewType={viewType} />
)}
{(() => {
const next = legs[i + 1];
if (!next) return null;
return <TransferBar leg={leg} nextLeg={next} viewType={viewType} />;
})()}
</Fragment>
))}
</div>
@@ -368,7 +370,7 @@ function getLegs(flight: { routeType: string; leg?: IFlightLeg; legs?: IFlightLe
export const OnlineBoardDetailsPage: FC<OnlineBoardDetailsPageProps> = ({
flightId,
locale,
canonicalOrigin,
canonicalOrigin: _canonicalOrigin,
}) => {
const { t } = useTranslation();
+7 -4
View File
@@ -19,9 +19,12 @@ interface ErrorBoundaryState {
* and fall back to English for any language we don't have coverage
* for. Mirrors what Angular's global ErrorHandler renders.
*/
const FALLBACK_RU = { title: "Что-то пошло не так", retry: "Повторить" } as const;
const FALLBACK_EN = { title: "Something went wrong", retry: "Retry" } as const;
const FALLBACK_STRINGS: Record<string, { title: string; retry: string }> = {
ru: { title: "Что-то пошло не так", retry: "Повторить" },
en: { title: "Something went wrong", retry: "Retry" },
ru: FALLBACK_RU,
en: FALLBACK_EN,
es: { title: "Algo salió mal", retry: "Reintentar" },
fr: { title: "Une erreur s'est produite", retry: "Réessayer" },
it: { title: "Qualcosa è andato storto", retry: "Riprova" },
@@ -32,10 +35,10 @@ const FALLBACK_STRINGS: Record<string, { title: string; retry: string }> = {
};
function pickStrings(): { title: string; retry: string } {
if (typeof window === "undefined") return FALLBACK_STRINGS.ru!;
if (typeof window === "undefined") return FALLBACK_RU;
const locale = resolveLocaleFromPath(window.location.pathname);
const lang = locale ? localeToLanguage(locale) : "ru";
return FALLBACK_STRINGS[lang] ?? FALLBACK_STRINGS.en!;
return FALLBACK_STRINGS[lang] ?? FALLBACK_EN;
}
/**
+8 -1
View File
@@ -58,7 +58,14 @@ const ERROR_CONFIG: Record<string, ErrorConfig> = {
},
};
const FALLBACK_CONFIG: ErrorConfig = ERROR_CONFIG["500"]!;
const FALLBACK_CONFIG: ErrorConfig = {
titleKey: "PAGE500.HEADER",
descriptionKey: "PAGE500.DESCRIPTION",
image: "/assets/img/lady500.png",
buyTicketKey: "PAGE500.BUY-TICKET",
homeKey: "PAGE500.TO-HOME",
supportKey: "PAGE500.SUPPORT",
};
export interface ErrorPageProps {
/** HTTP status code ("404", "500", "503"). Unknown codes fall back to 500. */