Skip to content

Add support for params generic in useRoute #1160

Open
@fyapy

Description

What problem does this feature solve?

Typing of params from useRoute.

When you have function with typed arguments

const someFn = (id: string, type: ResourceType) => {}

And when you try to pass a route.params as an argument

const route = useRoute()
someFn(route.params.resourceId, route.params.type)

You will get error

Argument of type 'string | string[]' is not assignable to parameter of type 'string'.
Type 'string[]' is not assignable to type 'string'.

Screenshot of problem

image

What does the proposed API look like?

type Params = {
    id: string
    type: ResourceType
}
const route = useRoute<Params>() // route.params will be typed

Pull Request

#1159

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthas workaroundA workaround has been found to deal with the issuetypescriptProblem related to TS typings

    Type

    No type

    Projects

    • Status

      🆕 Triaging

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions