Closed mathewcst closed 1 year ago
Would casting the array with routes as const
solve the issue?
Yes, casting the array as const removes the warning, but feels weird to do so tbh.
It makes sense if you think about it 😄 In the current form the path
property type is just a string
. You can just do menu[0].path = 'foobar'
. This would result in TS error so TS doesn't allow you to use this variable as a Link props, because Link in Tanstack Router is supposed to be typesafe. You can either mark it as const
which prevent mutations at all or add type declaration that will make sure that you can't assign incorrect path value here.
Your explanation makes total sense. Thank you so much for taking the time to do so. Sorry if this was as dumb question 😅. Gonna close the issue now.
It wasn't dumb at all and I'm happy to help!
Describe the bug
I'm using a map to define my website navigation. Passing gives me a typescript error.
Example code:
The error:
Your Example Website or App
https://stackblitz.com/edit/github-uj82gk?file=src/main.tsx
Steps to Reproduce the Bug or Issue
Expected behavior
To be able to use inside a map passing a variable as "to"
Screenshots or Videos
No response
Platform
Additional context
No response