From d3ffa735bf1e1456327834ae54a31b8adc86b4b6 Mon Sep 17 00:00:00 2001 From: Jalil Arfaoui Date: Wed, 7 Feb 2024 16:56:43 +0100 Subject: [PATCH] =?UTF-8?q?refactor:=20am=C3=A9liore=20l=C3=A9g=C3=A8remen?= =?UTF-8?q?t=20le=20typage=20(=C3=A9vite=20les=20any)=20(#2886)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- site/source/components/company/Details.tsx | 3 +-- site/source/design-system/field/Radio/Radio.tsx | 7 +++---- site/source/design-system/layout/Grid.tsx | 16 ++++------------ site/source/hooks/useAxeCoreAnalysis.ts | 6 ++---- .../assistants/demande-mobilité/EndBlock.tsx | 6 +----- site/source/pages/statistiques/Chart.tsx | 10 ++++++++-- site/source/types/iframe-resizer.d.ts | 5 ----- .../types/react-signature-pad-wrapper.d.ts | 5 ----- site/test/persistence.test.ts | 9 ++++----- 9 files changed, 23 insertions(+), 44 deletions(-) delete mode 100644 site/source/types/react-signature-pad-wrapper.d.ts diff --git a/site/source/components/company/Details.tsx b/site/source/components/company/Details.tsx index 24138bddb..8c8d76abe 100644 --- a/site/source/components/company/Details.tsx +++ b/site/source/components/company/Details.tsx @@ -16,8 +16,7 @@ export function CompanyDetails({ headingTag = 'h2', }: { showSituation?: boolean - // eslint-disable-next-line @typescript-eslint/no-explicit-any - headingTag?: string | ComponentType | undefined + headingTag?: string | ComponentType | undefined }) { return ( diff --git a/site/source/design-system/field/Radio/Radio.tsx b/site/source/design-system/field/Radio/Radio.tsx index 4d3aa44da..152ae2ec5 100644 --- a/site/source/design-system/field/Radio/Radio.tsx +++ b/site/source/design-system/field/Radio/Radio.tsx @@ -1,7 +1,7 @@ import { useRadio } from '@react-aria/radio' import { RadioGroupState } from '@react-stately/radio' import { AriaRadioProps } from '@react-types/radio' -import { createContext, useContext, useRef } from 'react' +import React, { createContext, useContext, useRef } from 'react' import { css, styled } from 'styled-components' import { FocusStyle } from '@/design-system/global-style' @@ -12,8 +12,7 @@ export const RadioContext = createContext(null) type RadioProps = AriaRadioProps & { className?: string role?: string - // eslint-disable-next-line @typescript-eslint/no-explicit-any - visibleRadioAs?: string | React.ComponentType + visibleRadioAs?: string | React.ComponentType } // TDOO: isDisabled style @@ -137,7 +136,7 @@ export const VisibleRadio = styled.span<{ $inert?: boolean }>` ? theme.colors.bases.primary[500] : theme.colors.bases.primary[700] }; - } : + } : ` : css` &:hover { diff --git a/site/source/design-system/layout/Grid.tsx b/site/source/design-system/layout/Grid.tsx index a4d4800b7..0c065d39b 100644 --- a/site/source/design-system/layout/Grid.tsx +++ b/site/source/design-system/layout/Grid.tsx @@ -1,18 +1,12 @@ import { ComponentType, createContext, useContext } from 'react' import { css, styled } from 'styled-components' -import { Merge } from '@/types/utils' - import { SpacingKey } from '../theme' const breakPoints = ['$sm', '$md', '$lg', '$xl'] as const -type Distribute = T extends unknown - ? { [K in T]: U } - : never - type BreakPoint = '$xs' | (typeof breakPoints)[number] -type BreakPoints = Distribute +type BreakPoints = Record type ContainerContext = { $nbColumns: number @@ -87,7 +81,7 @@ const StyledGridContainer = styled.div>` ); ` -const StyledGridItem = styled.div>` +const StyledGridItem = styled.div` padding-left: ${({ theme, $columnSpacing }) => theme.spacing[$columnSpacing ?? 0]}; padding-top: ${({ theme, $rowSpacing }) => theme.spacing[$rowSpacing ?? 0]}; @@ -111,8 +105,7 @@ type GridContainerProps = { columnSpacing?: number rowSpacing?: number children: React.ReactNode - // eslint-disable-next-line @typescript-eslint/no-explicit-any - as?: string | ComponentType | undefined + as?: string | ComponentType | undefined } & React.ComponentPropsWithoutRef<'div'> function GridContainer({ @@ -145,8 +138,7 @@ function GridContainer({ type GridItemProps = { children?: React.ReactNode className?: string - // eslint-disable-next-line @typescript-eslint/no-explicit-any - as?: string | ComponentType | undefined + as?: string | ComponentType | undefined } & Partial> & React.ComponentPropsWithoutRef<'div'> diff --git a/site/source/hooks/useAxeCoreAnalysis.ts b/site/source/hooks/useAxeCoreAnalysis.ts index a0359937e..329454d83 100644 --- a/site/source/hooks/useAxeCoreAnalysis.ts +++ b/site/source/hooks/useAxeCoreAnalysis.ts @@ -5,10 +5,8 @@ export const useAxeCoreAnalysis = () => { const axeRef = useRef< | { default: ( - // eslint-disable-next-line @typescript-eslint/no-explicit-any - _React: any, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - _ReactDOM: any, + _React: unknown, + _ReactDOM: unknown, _timeout: number ) => Promise } diff --git a/site/source/pages/assistants/demande-mobilité/EndBlock.tsx b/site/source/pages/assistants/demande-mobilité/EndBlock.tsx index b18ad536d..9984f6e32 100644 --- a/site/source/pages/assistants/demande-mobilité/EndBlock.tsx +++ b/site/source/pages/assistants/demande-mobilité/EndBlock.tsx @@ -21,10 +21,6 @@ import { Body, Intro, SmallBody } from '@/design-system/typography/paragraphs' import PDFDocument from './PDFDocument' const IS_TOUCH_DEVICE = isOnTouchDevice() -type SignaturePadInstance = { - clear: () => void - toDataURL: () => string -} type EndBlockProps = { fields: Array @@ -35,7 +31,7 @@ export default function EndBlock({ fields, missingValues }: EndBlockProps) { const [isCertified, setCertified] = useState(false) const [place, setPlace] = useState() const engine = useContext(EngineContext) - const signatureRef = useRef() + const signatureRef = useRef(null) const tracker = useContext(TrackingContext) const { colors } = useTheme() if (missingValues.length) { diff --git a/site/source/pages/statistiques/Chart.tsx b/site/source/pages/statistiques/Chart.tsx index 7cb53b269..121cd27e9 100644 --- a/site/source/pages/statistiques/Chart.tsx +++ b/site/source/pages/statistiques/Chart.tsx @@ -251,11 +251,17 @@ function formatMonth(date: string | Date) { }) } +interface PayloadData { + payload: { + info: ReactNode + date: string | Date + } & Record[0]> +} + type CustomTooltipProps = { active?: boolean period: Period - // eslint-disable-next-line @typescript-eslint/no-explicit-any - payload?: any + payload?: [PayloadData] dataKeys: string[] } diff --git a/site/source/types/iframe-resizer.d.ts b/site/source/types/iframe-resizer.d.ts index ed89edb8c..c9f8b575a 100644 --- a/site/source/types/iframe-resizer.d.ts +++ b/site/source/types/iframe-resizer.d.ts @@ -1,8 +1,3 @@ -interface Window { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - parentIFrame?: any -} - // Types from @types/iframe-resizer are for V3 and we use V4 declare module 'iframe-resizer' { export const iframeResize: (options: unknown, id: string) => void diff --git a/site/source/types/react-signature-pad-wrapper.d.ts b/site/source/types/react-signature-pad-wrapper.d.ts deleted file mode 100644 index 2bd51a9bf..000000000 --- a/site/source/types/react-signature-pad-wrapper.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -declare module 'react-signature-pad-wrapper' { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const signaturePad: any - export default signaturePad -} diff --git a/site/test/persistence.test.ts b/site/test/persistence.test.ts index 533855da0..01af41d60 100644 --- a/site/test/persistence.test.ts +++ b/site/test/persistence.test.ts @@ -1,7 +1,6 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ import { createMemoryHistory } from 'history' import { DottedName } from 'modele-social' -import { createStore } from 'redux' +import { createStore, Store, StoreEnhancer } from 'redux' import { beforeEach, describe, expect, it, vi } from 'vitest' import { setupSimulationPersistence } from '@/storage/persistSimulation' @@ -38,14 +37,14 @@ const initialSimulation: Simulation = { } describe('[persistence] When simulation persistence is setup', () => { - let store: any + let store: Store const setItemSpy = vi.spyOn(safeLocalStorage, 'setItem') beforeEach(() => { store = createStore(reducers, { simulation: initialSimulation, activeTargetInput: 'sometargetinput', - } as any) + } as unknown as StoreEnhancer) setupSimulationPersistence(store, 0) }) @@ -72,7 +71,7 @@ describe('[persistence] When simulation config is set', () => { const serializedPreviousSimulation = '{"situation":{"dotted name . other":"42"},"activeTargetInput":"someothertargetinput","foldedSteps":["someotherstep"]}' - let store: any + let store: Store vi.spyOn(safeLocalStorage, 'getItem').mockReturnValue( serializedPreviousSimulation