primefaces / sakai-react

Free React Admin Template
https://sakai.primereact.org
MIT License
849 stars 553 forks source link

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

Open ricardoc05 opened 9 months ago

ricardoc05 commented 9 months ago

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!

thesohailjafri commented 4 months ago

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