sakai-react icon indicating copy to clipboard operation
sakai-react copied to clipboard

TypeScript Error in AppMenuitem.tsx: Argument of type 'string | null' not assignable to parameter of type 'string'

Open ricardoc05 opened this issue 2 years ago • 1 comments

Hello, I'm encountering a TypeScript error in my React project that I'm having trouble resolving. The issue is in the file AppMenuitem.tsx, specifically at line 29. The error message is as follows: onRouteChange(pathname): Argument of type 'string | null' is not assignable to parameter of type 'string'. Type 'null' is not assignable to type 'string'.ts(2345). This error occurs when I try to pass pathname, which can be either a string or null, to the onRouteChange function that expects a parameter of type string. I've tried a few different approaches to solve this, such as checking for null before calling the function and using the non-null assertion operator, but I'm not sure if these are the best practices or if there's a more appropriate solution. Could someone please help me understand the best way to handle this type of error? Any guidance or suggestions on how to properly type this scenario or refactor the code would be greatly appreciated. Thank you in advance for your help!

ricardoc05 avatar Dec 03 '23 03:12 ricardoc05

try using a if block to check type if(typeof pathname==='string') onRouteChange(pathname)

thesohailjafri avatar May 20 '24 08:05 thesohailjafri