Reputation: 21
I am having this error: Argument of type 'string | undefined' is not assignable to parameter of type 'string'. Type 'undefined' is not assignable to type 'string'. TS2345
if (menu.authenticated && menu.canView?.includes(profile?.accountType)) {
| ^**Error is here**
123 | return loggedInUser && <MenuItem key={menu.resource} {...menu} />;
124 | } else {
125 | return !loggedInUser && <MenuItem key={menu.resource} {...menu} />;
Upvotes: 0
Views: 275
Reputation: 6838
The argument to menu.canView?.includes
has to be of type string
, but profile?.accountType
is of type string | undefined
.
You can fix the condition with
if (menu.authenticated && profile && menu.canView?.includes(profile.accountType)) {
Upvotes: 1