From b7b1a018198c157ae0ec0532dacde14f3f18aadb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rialland?= Date: Tue, 1 Aug 2023 11:41:01 +0200 Subject: [PATCH] Fix types error --- package.json | 3 ++- site/source/components/Distribution.tsx | 22 +++++++++++++--------- site/source/entries/entry-iframe.ts | 7 +++++-- site/tsconfig.json | 8 +++++++- yarn.lock | 22 ---------------------- 5 files changed, 27 insertions(+), 35 deletions(-) diff --git a/package.json b/package.json index b9c654e70..c597f5c93 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,8 @@ }, "resolutions": { "rollup": "^3.10.0", - "@types/koa": "^2.13.6" + "@types/koa": "^2.13.6", + "@types/react": "^18.2.18" }, "packageManager": "yarn@3.5.0", "engines": { diff --git a/site/source/components/Distribution.tsx b/site/source/components/Distribution.tsx index 4814d5d27..81d3372d0 100644 --- a/site/source/components/Distribution.tsx +++ b/site/source/components/Distribution.tsx @@ -17,15 +17,19 @@ export default function Distribution() { const engine = useContext(EngineContext) const distribution = ( getCotisationsBySection(useEngine().getParsedRules()) - .map(([section, cotisations]) => [ - section, - cotisations - .map((c) => engine.evaluate({ valeur: c, unité: targetUnit })) - .reduce( - (acc, evaluation) => acc + ((evaluation?.nodeValue as number) || 0), - 0 - ), - ]) + .map( + ([section, cotisations]) => + [ + section, + cotisations + .map((c) => engine.evaluate({ valeur: c, unité: targetUnit })) + .reduce( + (acc, evaluation) => + acc + ((evaluation?.nodeValue as number) || 0), + 0 + ), + ] as const + ) .filter(([, value]) => value > 0) as Array<[DottedName, number]> ).sort(([, a], [, b]) => b - a) const maximum = Math.max(...distribution.map(([, value]) => value)) diff --git a/site/source/entries/entry-iframe.ts b/site/source/entries/entry-iframe.ts index 25d2aa7ba..b05e67b93 100644 --- a/site/source/entries/entry-iframe.ts +++ b/site/source/entries/entry-iframe.ts @@ -10,15 +10,18 @@ **/ // @ts-ignore ignore file not exist error -import simulationData from '../public/simulation-data-title.json' +import simulationData from '../public/simulation-data-title.json' assert { type: 'json' } import { hexToHSL } from '../utils/hexToHSL' +type KeyofSimulationData = keyof typeof simulationData + const script = document.currentScript if (!script) { throw new Error('document.currentScript is null or undefined') } const iframePath = - (script.dataset.module as keyof typeof simulationData | undefined) || + // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents + (script.dataset.module as KeyofSimulationData | undefined) || 'simulateur-embauche' const moduleData = simulationData[iframePath] diff --git a/site/tsconfig.json b/site/tsconfig.json index f564091ac..95472235f 100644 --- a/site/tsconfig.json +++ b/site/tsconfig.json @@ -15,7 +15,13 @@ "@/*": ["*"] }, "types": ["vite/client", "vite-plugin-pwa/client"], - "typeRoots": ["./node_modules/@types", "./types/"], + "typeRoots": [ + "../node_modules/@types", + "../node_modules", + "./node_modules/@types", + "./node_modules", + "./types" + ], "noEmit": true, "strict": true }, diff --git a/yarn.lock b/yarn.lock index 8ad2455f1..f536d5a26 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10509,28 +10509,6 @@ __metadata: languageName: node linkType: hard -"@types/react@npm:*": - version: 18.0.25 - resolution: "@types/react@npm:18.0.25" - dependencies: - "@types/prop-types": "*" - "@types/scheduler": "*" - csstype: ^3.0.2 - checksum: 231d658c45abdef044a716b4502774f1585d8336d73b2f5bd68f181acbfc874b7a457686ecd29b415b43ed0922c309bab7e2cf96832d188a3f4f1b02f2af760a - languageName: node - linkType: hard - -"@types/react@npm:>=16": - version: 18.0.35 - resolution: "@types/react@npm:18.0.35" - dependencies: - "@types/prop-types": "*" - "@types/scheduler": "*" - csstype: ^3.0.2 - checksum: e65670397216e037b150a509ec08189140b4c20b82b612ac00b2a7133202be2d1def1e7ee69617b2df06ab4c00c43c4ee23e84788ad661aea9664da2f27c518a - languageName: node - linkType: hard - "@types/react@npm:^18.2.18": version: 18.2.18 resolution: "@types/react@npm:18.2.18"