Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: useLocation supports generics #9164

Closed
guaijie opened this issue Aug 18, 2022 · 1 comment
Closed

[Feature]: useLocation supports generics #9164

guaijie opened this issue Aug 18, 2022 · 1 comment
Labels

Comments

@guaijie
Copy link

guaijie commented Aug 18, 2022

What is the new or updated feature that you are suggesting?

type State = { from : string; base: string}
const location = useLocation()

// types
export declare function useLocation<T = unknown>(): Location;
export interface Location extends Path {
state: T;
key: Key;
}

Why should this feature be included?

Better type inference experience

@timdorr
Copy link
Member

timdorr commented Aug 18, 2022

This would actually remove type safety, as you would be overriding state to that type. You should be using type narrowing to determine the type of state safely. A generic would be a hack to force that to work.

#8370 (comment)
#8396 (comment)

@timdorr timdorr closed this as not planned Won't fix, can't repro, duplicate, stale Aug 18, 2022
brophdawg11 pushed a commit that referenced this issue Apr 23, 2024
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants