diff --git a/scripts/noUncheckedIndexedAccess_snapshot.txt b/scripts/noUncheckedIndexedAccess_snapshot.txt index b85704ae670..c061f49735c 100644 --- a/scripts/noUncheckedIndexedAccess_snapshot.txt +++ b/scripts/noUncheckedIndexedAccess_snapshot.txt @@ -1,26 +1,5 @@ -./src/cheatcodes/hooks/useSomeOfferId.ts:24 -./src/features/bookOffer/components/BookHourChoice.tsx:122 -./src/features/bookOffer/components/Calendar/useMarkedDates.native.test.ts:35 -./src/features/bookOffer/components/Calendar/useMarkedDates.native.test.ts:41 -./src/features/bookOffer/components/Calendar/useMarkedDates.native.test.ts:59 -./src/features/bookOffer/components/Calendar/useMarkedDates.native.test.ts:61 -./src/features/bookOffer/components/Calendar/useMarkedDates.native.test.ts:72 -./src/features/bookOffer/components/Calendar/useMarkedDates.native.test.ts:74 -./src/features/bookOffer/components/Calendar/useMarkedDates.native.test.ts:85 -./src/features/bookOffer/components/Calendar/useMarkedDates.native.test.ts:87 ./src/features/bookOffer/helpers/useReviewInAppInformation.ts:16 -./src/features/bookOffer/helpers/useRotatingText.ts:44 -./src/features/bookOffer/helpers/useRotatingText.ts:47 -./src/features/bookOffer/helpers/useRotatingText.ts:54 -./src/features/bookOffer/helpers/useRotatingText.ts:57 -./src/features/culturalSurvey/helpers/useGetNextQuestion.ts:13 ./src/features/culturalSurvey/pages/CulturalSurveyQuestions.native.test.tsx:234 -./src/features/deeplinks/helpers/getScreenFromDeeplink.ts:13 -./src/features/deeplinks/helpers/getScreenFromDeeplink.ts:15 -./src/features/deeplinks/helpers/getScreenFromDeeplink.ts:17 -./src/features/deeplinks/helpers/getScreenFromDeeplink.ts:19 -./src/features/deeplinks/helpers/getScreenFromDeeplink.ts:22 -./src/features/deeplinks/helpers/getScreenFromDeeplink.ts:24 ./src/features/home/api/helpers/mapVenuesDataAndModules.ts:13 ./src/features/home/api/helpers/mapVenuesDataAndModules.ts:15 ./src/features/home/components/modules/OffersModule.tsx:69 @@ -36,21 +15,11 @@ ./src/features/navigation/RootNavigator/linking/getNestedNavigationFromState.ts:14 ./src/features/navigation/RootNavigator/linking/getNestedNavigationFromState.ts:16 ./src/features/navigation/RootNavigator/linking/getNestedNavigationFromState.ts:19 -./src/features/navigation/RootNavigator/linking/getScreenConfig.test.ts:75 -./src/features/navigation/RootNavigator/linking/getScreenConfig.test.ts:81 -./src/features/navigation/RootNavigator/linking/getScreenConfig.test.ts:87 -./src/features/navigation/RootNavigator/linking/getScreenConfig.test.ts:93 -./src/features/navigation/RootNavigator/linking/getScreenConfig.test.ts:99 ./src/features/navigation/helpers/useCurrentRoute.ts:4 ./src/features/navigation/helpers/usePreviousRoute.ts:4 ./src/features/navigation/sanitizeNavigationState.ts:5 ./src/features/offer/components/OfferPlaylistList/OfferPlaylistList.native.test.tsx:110 ./src/features/offer/components/OfferPlaylistList/OfferPlaylistList.native.test.tsx:76 -./src/features/offer/components/VenueSelectionListItem/VenueSelectionListItem.web.tsx:74 -./src/features/offer/components/VenueSelectionListItem/VenueSelectionListItem.web.tsx:76 -./src/features/offer/components/VenueSelectionListItem/VenueSelectionListItem.web.tsx:81 -./src/features/offer/components/VenueSelectionListItem/VenueSelectionListItem.web.tsx:83 -./src/features/offer/components/VenueSelectionListItem/VenueSelectionListItem.web.tsx:85 ./src/features/profile/components/CreditInfo/CreditProgressBar.tsx:32 ./src/features/search/components/sections/Accessibility/Accessibility.tsx:33 ./src/features/search/pages/SuggestedPlacesOrVenues/SuggestedVenues.native.test.tsx:43 @@ -62,12 +31,6 @@ ./src/libs/hooks/useTimer.native.test.ts:34 ./src/libs/hooks/useTimer.native.test.ts:53 ./src/libs/itinerary/useItinerary.native.test.ts:61 -./src/libs/location/geolocation/requestGeolocPermission/requestGeolocPermission.android.ts:11 -./src/libs/location/geolocation/requestGeolocPermission/requestGeolocPermission.android.ts:15 -./src/libs/location/geolocation/requestGeolocPermission/requestGeolocPermission.android.ts:17 -./src/libs/location/geolocation/requestGeolocPermission/requestGeolocPermission.android.ts:22 -./src/libs/location/geolocation/requestGeolocPermission/requestGeolocPermission.android.ts:24 -./src/libs/location/geolocation/requestGeolocPermission/requestGeolocPermission.android.ts:9 ./src/libs/parsers/formatDates.ts:105 ./src/libs/parsers/formatDates.ts:107 ./src/libs/parsers/formatDates.ts:112 diff --git a/src/cheatcodes/hooks/useSomeOfferId.ts b/src/cheatcodes/hooks/useSomeOfferId.ts index 491f9126033..427dd0516f5 100644 --- a/src/cheatcodes/hooks/useSomeOfferId.ts +++ b/src/cheatcodes/hooks/useSomeOfferId.ts @@ -21,8 +21,11 @@ export const useSomeOfferId = () => { aroundPlaceRadius: 'all', }, }) - // @ts-expect-error: because of noUncheckedIndexedAccess - .then((response) => setOfferId(Number.parseInt(response.hits[0].objectID))) + .then((response) => { + if (response.hits[0]) { + setOfferId(Number.parseInt(response.hits[0].objectID)) + } + }) .catch(() => { // The cheatcodes are only in testing // eslint-disable-next-line no-console diff --git a/src/features/bookOffer/components/BookHourChoice.tsx b/src/features/bookOffer/components/BookHourChoice.tsx index 195d8c06003..8fbad1993a9 100644 --- a/src/features/bookOffer/components/BookHourChoice.tsx +++ b/src/features/bookOffer/components/BookHourChoice.tsx @@ -118,8 +118,7 @@ export const BookHourChoice = () => { const selectHour = (hour: string, stockFromHour: OfferStockResponse[]) => { dispatch({ type: 'SELECT_HOUR', payload: hour }) - if (stockFromHour.length === 1) { - // @ts-expect-error: because of noUncheckedIndexedAccess + if (stockFromHour.length === 1 && stockFromHour[0]) { dispatch({ type: 'SELECT_STOCK', payload: stockFromHour[0].id }) } if (!isDuo) { diff --git a/src/features/bookOffer/components/Calendar/useMarkedDates.native.test.ts b/src/features/bookOffer/components/Calendar/useMarkedDates.native.test.ts index b26862fc671..7b633b82d42 100644 --- a/src/features/bookOffer/components/Calendar/useMarkedDates.native.test.ts +++ b/src/features/bookOffer/components/Calendar/useMarkedDates.native.test.ts @@ -32,14 +32,12 @@ describe('useMarkedDates()', () => { it('should mark selected date correctly', () => { let hook = renderHook(() => useMarkedDates([offerStockResponseSnap], credit)) - // @ts-expect-error: because of noUncheckedIndexedAccess - expect(hook.result.current['2021-01-01'].selected).toBe(true) + expect(hook.result.current['2021-01-01']?.selected).toBe(true) mockBookingState.date = new Date(2021, 4, 4) hook = renderHook(() => useMarkedDates([offerStockResponseSnap], credit)) - // @ts-expect-error: because of noUncheckedIndexedAccess - expect(hook.result.current['2021-01-01'].selected).toBe(false) + expect(hook.result.current['2021-01-01']?.selected).toBe(false) }) it('should skip stocks without date', () => { @@ -56,10 +54,8 @@ describe('useMarkedDates()', () => { ] const { result } = renderHook(() => useMarkedDates(stocks, 2000)) - // @ts-expect-error: because of noUncheckedIndexedAccess - expect(result.current['2021-01-01'].price).toEqual(2000) - // @ts-expect-error: because of noUncheckedIndexedAccess - expect(result.current['2021-01-01'].status).toEqual('BOOKABLE') + expect(result.current['2021-01-01']?.price).toEqual(2000) + expect(result.current['2021-01-01']?.status).toEqual('BOOKABLE') }) it('should return the correct status and price for non bookable stocks', () => { @@ -69,10 +65,8 @@ describe('useMarkedDates()', () => { ] const { result } = renderHook(() => useMarkedDates(stocks, 2000)) - // @ts-expect-error: because of noUncheckedIndexedAccess - expect(result.current['2021-01-01'].price).toEqual(200) - // @ts-expect-error: because of noUncheckedIndexedAccess - expect(result.current['2021-01-01'].status).toEqual('NOT_BOOKABLE') + expect(result.current['2021-01-01']?.price).toEqual(200) + expect(result.current['2021-01-01']?.status).toEqual('NOT_BOOKABLE') }) it('should select the bookable stock for a particular date even if not enough credit', () => { @@ -82,9 +76,7 @@ describe('useMarkedDates()', () => { ] const { result } = renderHook(() => useMarkedDates(stocks, 200)) - // @ts-expect-error: because of noUncheckedIndexedAccess - expect(result.current['2021-01-01'].price).toEqual(2000) - // @ts-expect-error: because of noUncheckedIndexedAccess - expect(result.current['2021-01-01'].status).toEqual('NOT_BOOKABLE') + expect(result.current['2021-01-01']?.price).toEqual(2000) + expect(result.current['2021-01-01']?.status).toEqual('NOT_BOOKABLE') }) }) diff --git a/src/features/bookOffer/helpers/useRotatingText.ts b/src/features/bookOffer/helpers/useRotatingText.ts index ee7d60ff215..fccd650459a 100644 --- a/src/features/bookOffer/helpers/useRotatingText.ts +++ b/src/features/bookOffer/helpers/useRotatingText.ts @@ -41,19 +41,15 @@ export function useRotatingText( } // the condition handles loop repetition from start - // @ts-expect-error: because of noUncheckedIndexedAccess - return currentMessage.keepDuration ? 0 : prev + return currentMessage?.keepDuration ? 0 : prev }) - // @ts-expect-error: because of noUncheckedIndexedAccess - }, currentMessage.keepDuration) + }, currentMessage?.keepDuration) } return () => { clearInterval(intervalRef.current) } - // @ts-expect-error: because of noUncheckedIndexedAccess - }, [currentMessage.keepDuration, shouldRun]) + }, [currentMessage?.keepDuration, shouldRun]) - // @ts-expect-error: because of noUncheckedIndexedAccess - return currentMessage.message + return currentMessage?.message ?? '' } diff --git a/src/features/culturalSurvey/helpers/useGetNextQuestion.ts b/src/features/culturalSurvey/helpers/useGetNextQuestion.ts index 3792e26c0f2..704e6d3053c 100644 --- a/src/features/culturalSurvey/helpers/useGetNextQuestion.ts +++ b/src/features/culturalSurvey/helpers/useGetNextQuestion.ts @@ -7,12 +7,9 @@ export const useGetNextQuestion = (currentQuestion: CulturalSurveyQuestionEnum) const nextQuestionIndex = questionsToDisplay.indexOf(currentQuestion) + 1 const isCurrentQuestionLastQuestion = nextQuestionIndex === questionsToDisplay.length - let nextQuestion = currentQuestion - - if (!isCurrentQuestionLastQuestion) { - // @ts-expect-error: because of noUncheckedIndexedAccess - nextQuestion = questionsToDisplay[nextQuestionIndex] - } + const nextQuestion = isCurrentQuestionLastQuestion + ? currentQuestion + : questionsToDisplay[nextQuestionIndex] return { isCurrentQuestionLastQuestion, nextQuestion } } diff --git a/src/features/culturalSurvey/pages/CulturalSurveyQuestions.tsx b/src/features/culturalSurvey/pages/CulturalSurveyQuestions.tsx index 1790f0f2acb..1a63dba80b5 100644 --- a/src/features/culturalSurvey/pages/CulturalSurveyQuestions.tsx +++ b/src/features/culturalSurvey/pages/CulturalSurveyQuestions.tsx @@ -111,7 +111,7 @@ export function CulturalSurveyQuestions({ route }: CulturalSurveyQuestionsProps) const navigateToNextQuestion = () => { if (isCurrentQuestionLastQuestion) { postCulturalSurveyAnswers({ answers }) - } else { + } else if (nextQuestion) { push('CulturalSurveyQuestions', { question: nextQuestion }) } } diff --git a/src/features/deeplinks/helpers/getScreenFromDeeplink.ts b/src/features/deeplinks/helpers/getScreenFromDeeplink.ts index 35fcc6cc640..ad266c8df00 100644 --- a/src/features/deeplinks/helpers/getScreenFromDeeplink.ts +++ b/src/features/deeplinks/helpers/getScreenFromDeeplink.ts @@ -10,19 +10,13 @@ export function getScreenFromDeeplink(url: string): DeeplinkParts { } const navigationState = linking.getStateFromPath(pathWithQueryString, linking.config) const route = getLastRouteFromState(navigationState) - // @ts-expect-error: because of noUncheckedIndexedAccess - const screen = route.name - // @ts-expect-error: because of noUncheckedIndexedAccess - let params = route.params - // @ts-expect-error: because of noUncheckedIndexedAccess - if (route.state) { - // @ts-expect-error: because of noUncheckedIndexedAccess + const screen = route?.name + let params = route?.params + if (route?.state) { const nestedRoute = getLastRouteFromState(route.state) params = { - // @ts-expect-error: because of noUncheckedIndexedAccess - screen: nestedRoute.name, - // @ts-expect-error: because of noUncheckedIndexedAccess - params: nestedRoute.params, + screen: nestedRoute?.name, + params: nestedRoute?.params, } } return { screen, params } as DeeplinkParts diff --git a/src/features/navigation/RootNavigator/linking/getScreenConfig.test.ts b/src/features/navigation/RootNavigator/linking/getScreenConfig.test.ts index de7730834df..284b5b8d365 100644 --- a/src/features/navigation/RootNavigator/linking/getScreenConfig.test.ts +++ b/src/features/navigation/RootNavigator/linking/getScreenConfig.test.ts @@ -72,32 +72,27 @@ describe('getScreensAndConfig()', () => { _DeeplinkOnlyLogin1: { path: 'connexion', parse }, }) expect(Screens).toHaveLength(5) - // @ts-expect-error: because of noUncheckedIndexedAccess - expect(Screens[0].props).toEqual({ + expect(Screens[0]?.props).toEqual({ name: 'Offer', component: expect.any(Object), options: { title: 'Offer title' }, }) - // @ts-expect-error: because of noUncheckedIndexedAccess - expect(Screens[1].props).toEqual({ + expect(Screens[1]?.props).toEqual({ name: '_DeeplinkOnlyOffer1', component: expect.any(Object), options: { title: 'Offer title' }, }) - // @ts-expect-error: because of noUncheckedIndexedAccess - expect(Screens[2].props).toEqual({ + expect(Screens[2]?.props).toEqual({ name: '_DeeplinkOnlyOffer2', component: expect.any(Object), options: { title: 'Offer title' }, }) - // @ts-expect-error: because of noUncheckedIndexedAccess - expect(Screens[3].props).toEqual({ + expect(Screens[3]?.props).toEqual({ name: 'Login', component: expect.any(Object), options: { title: 'Login title' }, }) - // @ts-expect-error: because of noUncheckedIndexedAccess - expect(Screens[4].props).toEqual({ + expect(Screens[4]?.props).toEqual({ name: '_DeeplinkOnlyLogin1', component: expect.any(Object), options: { title: 'Login title' }, diff --git a/src/features/offer/components/VenueSelectionListItem/VenueSelectionListItem.web.tsx b/src/features/offer/components/VenueSelectionListItem/VenueSelectionListItem.web.tsx index ade605a0446..322c68b8b1c 100644 --- a/src/features/offer/components/VenueSelectionListItem/VenueSelectionListItem.web.tsx +++ b/src/features/offer/components/VenueSelectionListItem/VenueSelectionListItem.web.tsx @@ -36,6 +36,7 @@ export function VenueSelectionListItem({ index, style, data }: Readonly 0 const shouldDisplayHeader = isHeader && hasHits + const item = data.items[index] if (shouldDisplayHeader) { return ( @@ -66,24 +67,23 @@ export function VenueSelectionListItem({ index, style, data }: Readonly data.onItemSelect(data.items[index].offerId)} - // @ts-expect-error: because of noUncheckedIndexedAccess - isSelected={data.selectedItem === data.items[index].offerId} + onSelect={() => data.onItemSelect(item.offerId)} + isSelected={data.selectedItem === item?.offerId} testID="venue-selection-list-item" render={({ isHover }) => ( )} diff --git a/src/libs/location/geolocation/requestGeolocPermission/requestGeolocPermission.android.ts b/src/libs/location/geolocation/requestGeolocPermission/requestGeolocPermission.android.ts index a7e4b17eb70..3a3edd9bead 100644 --- a/src/libs/location/geolocation/requestGeolocPermission/requestGeolocPermission.android.ts +++ b/src/libs/location/geolocation/requestGeolocPermission/requestGeolocPermission.android.ts @@ -4,25 +4,22 @@ import { AskGeolocPermission } from 'libs/location/types' import { GeolocPermissionState } from '../enums' +const ACCESS_FINE_LOCATION = 'android.permission.ACCESS_FINE_LOCATION' +const ACCESS_COARSE_LOCATION = 'android.permission.ACCESS_COARSE_LOCATION' + const requestGeolocPermissionSystem: AskGeolocPermission = async () => { const permissions = await PermissionsAndroid.requestMultiple([ - // @ts-expect-error: because of noUncheckedIndexedAccess - PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, - // @ts-expect-error: because of noUncheckedIndexedAccess - PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION, + ACCESS_FINE_LOCATION, + ACCESS_COARSE_LOCATION, ]) if ( - // @ts-expect-error: because of noUncheckedIndexedAccess - permissions[PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION] === 'granted' || - // @ts-expect-error: because of noUncheckedIndexedAccess - permissions[PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION] === 'granted' + permissions[ACCESS_FINE_LOCATION] === 'granted' || + permissions[ACCESS_COARSE_LOCATION] === 'granted' ) { return GeolocPermissionState.GRANTED } else if ( - // @ts-expect-error: because of noUncheckedIndexedAccess - permissions[PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION] === 'never_ask_again' || - // @ts-expect-error: because of noUncheckedIndexedAccess - permissions[PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION] === 'never_ask_again' + permissions[ACCESS_FINE_LOCATION] === 'never_ask_again' || + permissions[ACCESS_COARSE_LOCATION] === 'never_ask_again' ) { return GeolocPermissionState.NEVER_ASK_AGAIN }