I am making a chart in react app with typescript and implementation wise things are completed.
Issue is that I am receiving the error in the line,
backgroundColor: gradientFill
? gradientFill
: chartRef.current.data.datasets[0].backgroundColor,
Error states that,
Object is possibly 'null'.
Working Example:
Error occurs in line number 24 .
Things tried:
chartRef?.current?.data.datasets[0].backgroundColor
This results in the error Property 'data' does not exist on type 'never'..
Could you please kindly help me to get rid of the error? Thanks in advance.
Context: This question is related to my previous question and this answer.