Property does not exist on type 'never'

React 18 for beginners’ course - Expense tracker project.
In the video where Mosh shows how to complete the project, he creates an useState hook and he initializes it with some sample data to evaluate further functionalities.

const [expenses, setExpenses] = useState([]);

This useState should initialize with an empty array, without any sample data. This array will be populated when you submit each expense through the expense form.

When I delete the sample data, I get the following error message when trying to render objects of that empty array.

Property ‘category’ does not exist on type ‘never’

How can I get rid of this typescript error? The application still works but I have this error on my code.


You’ll need to post more of your code. There is a place somewhere in your code that you are accessing variableNameIDontKnowWhat.category. That’s what the error is saying. Can you post a small section of your code that is accessing the property ‘category’?

I was able to fix it. Thanks anyway for your support.

1 Like