Skip to content

Possible useParams TypeScript broken definition #8200

@DragosMocrii

Description

@DragosMocrii
import { useParams } from "react-router-dom"

interface JobPageRouteParams {
    jobId: string
}

const MyComponent = () => {
const { jobId } = useParams<JobPageRouteParams>();
}

gives an error: Type 'JobPageRouteParams' does not satisfy the constraint 'string'. .

The definition on useParams is

export declare function useParams<Key extends string = string>(): Readonly<Params<Key>>;

which means that the generic type is supposed to be a string?? Am I missing something here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions