Skip to content

[Types]: Narrow types of hash and search returned by useLocation #11254

@lensbart

Description

@lensbart

Describe what's incorrect/missing in the documentation

Hello,

The documentation comment for useLocation().hash states:

A URL fragment identifier, beginning with a #.

If this is a strict rule, it would be convenient if these values could be typed as '' | `#${string}` instead of string. This is especially useful if hash is passed along to another function that impose a stricter input type, and will allow us to avoid an if/else clause or having to type cast.

Likewise, the documentation comment for useLocation().search states:

A URL search string, beginning with a ?.

So this value could be typed as '' | `?${string}` instead of string. (Alternatively, '' | `?${string}=${string}` or '' | `?${string}=${string}` | `?${string}=${string}&${string}=${string}` would be valid too. However, this would probably add unnecessary confusion because it doesn’t suggest that the string can contain multiple &${string}=${string} segments).

I’m willing to submit a PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions