Skip to content

Commit 102aa66

Browse files
authored
Merge pull request #2002 from IFRCGo/feature/enable-no-unchecked-indexed-access
Enable noUncheckedIndexedAccess rule
2 parents a2f00a9 + 0a77a9d commit 102aa66

File tree

53 files changed

+187
-172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+187
-172
lines changed

app/src/App/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function Application() {
105105
}
106106

107107
const updatedAlert = {
108-
...prevAlerts[i],
108+
...prevAlerts[i]!,
109109
paramsWithoutName,
110110
};
111111

app/src/components/domain/AppealsOverYearsChart/MonthlyChart/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const dataKeyToClassNameMap = {
4444
dref: styles.dref,
4545
emergencyAppeal: styles.emergencyAppeal,
4646
};
47-
const classNameSelector = (dataKey: DATA_KEY) => dataKeyToClassNameMap[dataKey];
47+
const classNameSelector = (dataKey: DATA_KEY) => dataKeyToClassNameMap[dataKey]!;
4848
const xAxisFormatter = (date: Date) => date.toLocaleString(
4949
navigator.language,
5050
{ month: 'short' },
@@ -81,7 +81,8 @@ function MonthlyChart(props: Props) {
8181
);
8282

8383
const [activePointKey, setActivePointKey] = useState<string>(
84-
() => getFormattedDateKey(dateList[0]),
84+
// FIXME: add proper not null check
85+
() => getFormattedDateKey(dateList[0]!),
8586
);
8687

8788
const query = {

app/src/components/domain/AppealsOverYearsChart/YearlyChart/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const dataKeyToClassNameMap = {
4949
dref: styles.dref,
5050
emergencyAppeal: styles.emergencyAppeal,
5151
};
52-
const classNameSelector = (dataKey: DATA_KEY) => dataKeyToClassNameMap[dataKey];
52+
const classNameSelector = (dataKey: DATA_KEY) => dataKeyToClassNameMap[dataKey]!;
5353
const xAxisFormatter = (date: Date) => date.toLocaleString(
5454
navigator.language,
5555
{ year: 'numeric' },
@@ -68,7 +68,7 @@ function YearlyChart(props: Props) {
6868
const strings = useTranslation(i18n);
6969

7070
const [activePointKey, setActivePointKey] = useState<string>(
71-
() => getFormattedDateKey(dateList[dateList.length - 1]),
71+
() => getFormattedDateKey(dateList[dateList.length - 1]!),
7272
);
7373

7474
const queryParams = {

app/src/components/domain/GoMultiFileInput/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ interface FileUploadResult {
3737
const keySelector = (d: FileUploadResult) => d.id;
3838
const valueSelector = (d: FileUploadResult) => d.file;
3939

40-
function getFileNameFromUrl(urlString: string) {
40+
function getFileNameFromUrl(urlString: string | undefined) {
41+
if (isNotDefined(urlString)) {
42+
return undefined;
43+
}
44+
4145
const url = new URL(urlString);
4246
const splits = url.pathname.split('/');
4347
return splits[splits.length - 1];

app/src/components/domain/HighlightedOperations/OperationCard/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function OperationCard(props: Props) {
111111

112112
let countriesInfoDisplay = strings.operationCardNoCountryInvolved;
113113
if (countries.length === 1) {
114-
countriesInfoDisplay = countries[0].name ?? '?';
114+
countriesInfoDisplay = countries[0]!.name ?? '?';
115115
} else if (countries.length > 1) {
116116
countriesInfoDisplay = strings.operationCardInvolvesMultipleCountries;
117117
}

app/src/components/domain/HistoricalDataChart/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function isValidDisaster(
7474
if (isFalsyString(disaster.name)) {
7575
return false;
7676
}
77-
return validDisastersForChart[disaster.id];
77+
return validDisastersForChart[disaster.id]!;
7878
}
7979

8080
const hazardIdToColorMap: Record<number, string> = {

app/src/components/domain/RiskImminentEvents/MeteoSwiss/EventDetails/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function EventDetails(props: Props) {
126126

127127
if (impact_type.startsWith('exposed_population_')) {
128128
const windspeed = Number.parseInt(
129-
impact_type.split('exposed_population_')[1],
129+
impact_type.split('exposed_population_')[1]!,
130130
10,
131131
);
132132

app/src/components/domain/RiskSeasonalMap/index.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ interface TooltipContentProps {
9494
value: number;
9595
riskCategory: number;
9696
hazard_type: HazardType;
97-
hazard_type_display: string;
97+
hazard_type_display: string | undefined;
9898
}[];
9999
}
100100

@@ -603,12 +603,12 @@ function RiskSeasonalMap(props: Props) {
603603

604604
type RiskDataItemWithHazard = RiskDataItem & {
605605
hazard_type: HazardType;
606-
hazard_type_display: string;
606+
hazard_type_display: string | undefined;
607607
country_details: {
608608
id: number;
609609
name?: string | null;
610610
iso3?: string | null;
611-
}
611+
} | undefined;
612612
}
613613

614614
function groupByCountry(riskDataList: RiskDataItemWithHazard[] | undefined) {
@@ -647,7 +647,7 @@ function RiskSeasonalMap(props: Props) {
647647
const transformedList = mapToList(
648648
groupByCountry(riskDataList),
649649
(itemList, key) => {
650-
const firstItem = itemList[0];
650+
const firstItem = itemList[0]!;
651651
const valueListByHazard = itemList.map(
652652
(item) => {
653653
const value = getValueForSelectedMonths(
@@ -767,21 +767,25 @@ function RiskSeasonalMap(props: Props) {
767767
).sort((a, b) => compareNumber(a.riskCategorySum, b.riskCategorySum, -1));
768768
}
769769

770+
if (isNotDefined(data)) {
771+
return undefined;
772+
}
773+
770774
if (filters.riskMetric === 'displacement') {
771775
return transformRiskData(
772-
data?.displacement,
776+
data.displacement,
773777
);
774778
}
775779

776780
if (filters.riskMetric === 'exposure') {
777781
return transformRiskData(
778-
data?.exposure,
782+
data.exposure,
779783
);
780784
}
781785

782786
if (filters.riskMetric === 'riskScore') {
783787
const transformedData = transformRiskData(
784-
data?.riskScore,
788+
data.riskScore,
785789
'max',
786790
);
787791

app/src/components/domain/SeverityIndicator/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ function SeverityIndicator(props: Props) {
1717
title,
1818
className,
1919
} = props;
20-
const classNameMap: Record<number, string> = {
20+
21+
const classNameMap: Record<number, string | undefined> = {
2122
0: styles.yellow,
2223
1: styles.orange,
2324
2: styles.red,

app/src/hooks/useNumericChartData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function useNumericChartData<DATUM>(data: DATUM[] | null | undefined, options: O
169169

170170
const tickWithLowestOffset = [...potentialTicks].sort(
171171
(a, b) => compareNumber(a.rank, b.rank, -1),
172-
)[0];
172+
)[0]!;
173173

174174
return bound(
175175
tickWithLowestOffset.numTicks,

0 commit comments

Comments
 (0)