From 4ce71657c09ed983d396654cf738c27edd8af357 Mon Sep 17 00:00:00 2001 From: Jakob Langdal Date: Thu, 31 Mar 2022 13:18:39 +0000 Subject: [PATCH] Fix typescript errors --- components/home/home.tsx | 12 +++++++----- components/input-model/categorical-variable.tsx | 10 ++-------- components/layout/layout.tsx | 8 +++++--- components/plots/pareto-front-plot.tsx | 2 +- components/result-data/result-data.tsx | 4 ++-- components/upload-csv-button.tsx | 11 +++++++---- context/experiment-context.test.tsx | 16 +--------------- context/experiment-context.tsx | 16 +--------------- context/global-context.tsx | 2 +- hooks/useLocalStorageReducer.ts | 2 +- package.json | 1 + pages/_app.tsx | 6 +++--- pages/api/experiment/[id].tsx | 9 +++++++++ reducers/experiment-reducers.ts | 2 ++ store.ts | 2 +- tsconfig.json | 1 + utility/migration/migration.ts | 3 ++- yarn.lock | 5 +++++ 18 files changed, 52 insertions(+), 60 deletions(-) diff --git a/components/home/home.tsx b/components/home/home.tsx index 147f1745..3b282a55 100644 --- a/components/home/home.tsx +++ b/components/home/home.tsx @@ -45,7 +45,9 @@ export default function Home() { message: 'Drag file here', isError: false, }) - const [tempExperiment, setTempExperiment] = useState() + const [tempExperiment, setTempExperiment] = useState< + ExperimentType | undefined + >() const saveExperimentLocally = useCallback( (experiment: ExperimentType) => { @@ -79,7 +81,7 @@ export default function Home() { } const load = (reader: FileReader) => { - const binaryResult: string | ArrayBuffer = reader.result + const binaryResult: string | ArrayBuffer | null = reader.result try { const experiment: ExperimentType = JSON.parse(binaryResult as string) if (experiment.id === undefined) { @@ -125,7 +127,7 @@ export default function Home() { const getExperimentName = (key: string) => { try { - const json: any = JSON.parse(localStorage.getItem(key)) + const json: any = JSON.parse(localStorage.getItem(key) ?? '') const experiment: ExperimentType = json.experiment return !isEmpty(experiment.info.name) ? experiment.info.name : '-' } catch (e) { @@ -151,12 +153,12 @@ export default function Home() { } const handleOverwriteDialog = () => { - saveExperimentLocally(tempExperiment) + tempExperiment && saveExperimentLocally(tempExperiment) setTempExperiment(undefined) } const handleCreateDialog = () => { - saveExperimentLocally({ ...tempExperiment, id: uuid() }) + tempExperiment && saveExperimentLocally({ ...tempExperiment, id: uuid() }) setTempExperiment(undefined) } diff --git a/components/input-model/categorical-variable.tsx b/components/input-model/categorical-variable.tsx index e2b7c625..df8920d8 100644 --- a/components/input-model/categorical-variable.tsx +++ b/components/input-model/categorical-variable.tsx @@ -21,7 +21,7 @@ type CategoricalVariableProps = { export default function CategoricalVariable(props: CategoricalVariableProps) { const classes = useStyles() const { isDisabled, onAdded } = props - const [options, setOptions] = useState([]) + const [options, setOptions] = useState([]) const { register, handleSubmit, reset, formState, setError, clearErrors } = useForm() const isOptionsValid = useCallback(() => { @@ -57,7 +57,6 @@ export default function CategoricalVariable(props: CategoricalVariableProps) { <>