Hi i want to fix error "the left hand side of an arithematic operation must be of type 'any' 'number' 'bigint' or enum type" using react and typescript.
what i am trying to do?
i have code below,
const [progress, setProgress] = React.useState<any>(undefined);
const {
data: dataProgress,
} = useProgress({
variables: { id },
fetchPolicy: 'no-cache',
});
React.useEffect(() => {
if (status === EnumStatus.INITIAL || status === EnumStatus.FINISHED || status
=== EnumStatus.FAILED) {
setProgress(undefined);
}
if (status === EnumStatus.STARTED) {
setProgress(dataProgress);
}
}, [progress, setProgress, dataProgress]);
const completed = dataProgress
? dataProgress.dataProgress.completed: 0;
const total = dataProgress ? dataProgress.dataProgress.total: 0;
let value = 0;
if (completed > 0 && total > 0) {
value = (completed / total) * 100; //error here in place of completed and total
}
return (
<ProgressBar value={value}/>
);
I am querying useProgress to get data from api which is stored in dataProgress. this dataProgress has completed and total properties. i have to divide these values with 100 to get value which inturn will be passed as value prop to progress bar.
but i am encountering the error mentioned on line where i redefine value.
could someone help me fix this. thanks.
CodePudding user response:
try to cast it to number
value = Number((Number(completed) / Number(total)) * 100);