Closed Bobakanoosh closed 10 months ago
Yeah it's normal that's it's unknown, $typedRoute
and typescript can't know which route you're at unless you do if ($typedRoute.name === "xxxx")
before.
Solution would be to use useRoute
like this.
const {params} = useRoute('xxxxx')
// ^ typed
What do you think about at least making it any
instead of unknown
? That way it can at least be passed.
The whole point of this module is to be typesafe, you can just use $route
if you want any
Unfortunately I get this warning:
Type 'RouteParams' is not assignable to type '{ username: string | number; profileId: string | number; }'.ts(2322)
with
:to="{ name: $routesNames.siegeUsernameProfileId, params: $route.params }"
Then if you don't want type safety you can just add $route.params as any
@victorgarciaesgi
Yeah it's normal that's it's unknown,
$typedRoute
and typescript can't know which route you're at unless you doif ($typedRoute.name === "xxxx")
before. Solution would be to useuseRoute
like this.const {params} = useRoute('xxxxx') // ^ typed
is doing the following inside the page products/[slug].vue
without the the if
check safe?
const route = useRoute('products-slug')
if it is, would there be a build-time way to figure out in which pages/..
useRoute
is used and based on that automatically infer the route name?
I understand how this is impossible to determine at built time within other components but route components should work
Describe the bug I'm trying to do the following with a nested dynamic route like
/:username/:profileId
:But $typedRoute.params's default type is
unknown
.params
then complains with:Expected behavior It would be nice if the type inferred based on the
name
I gave (like how the params already does that). At a minimum, it would be nice if it wasany
so I could pass it without having to coalesce the type.Screenshots N/A
Environnement infos
Your
pages
folder structureRun
npx tree-node-cli {your page folder path}
Your nuxt.config.ts