1

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} />;
1
  • what's the data type of menu.authenticated and menu.canView? Commented Feb 16, 2022 at 9:43

1 Answer 1

1

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)) {
Sign up to request clarification or add additional context in comments.

1 Comment

maybe && profile.accountType as well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.