Hallo everyone, I need some help.
I am writing a redux-toolkit create function and it is the first time I am using typescript. Currently Vs-code underlines accessToken and tells me:
The property accessToken does not exist for the User type.ts(2339)
I googled this and have found, that I should add the property to the interface but this brought no solution. Here is my function:
Hello NielsDom, thanks for your response. I deleted the questionmark. But how I can set global state {accessToken:“”}. I have set an Interface user in the global.d.ts, there I have accessToken as string. User is an object array.
Hello NielsDom, I have tried all that, but the error stays. The interesting is, that when I hover accessToken, Vs-code tells me the correct type : user.accesstoken.
Hard to tell I would instead to do conditions with null or undefined, to put directly the state with a default empty string or number value in your User state, so you avoid to check each parent if they not exist (it is what I do in my projects). Moreover, it would declare the type directly, so you may not need interface