-
Notifications
You must be signed in to change notification settings - Fork 250
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
Improve accuracy of AuthState type definitions #201
Labels
enhancement
New feature or request
Comments
supermacro
changed the title
Improve accuracy of AuthState type definitioins
Improve accuracy of AuthState type definitions
Feb 19, 2021
Thanks for raising this @supermacro We can't change |
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the problem you'd like to have solved
Main Problem: Usage of
any
onUser
type and hard-to-find information on whatUser
really representsI personally learn more about a library and the set of its possible behaviours by reading the types. Unfortunately, when I stumble upon an
any
, not only do I not gain insight into the meaning of a type, I also now have to deal with extreme ambiguity in my own code.Specifically, I am referring to the
AuthState
interface which defines a field ofuser
of typeany
.Neither the code itself, nor the React SDK docs actually tell me what
user
really represents.I am inclined to believe that it actually represents an ID token given that when I
console.log
user
I get an object with asub
field.Secondary Problem: Potentially Non-Sensical Types
As it stands, the
AuthState
definition implies that you can have a state that is:What does
isLoading === true && isAuthenticated === true
mean? Is this a valid state? My intuition tells me it isn't, but maybe i'm wrong!I don't really want to cover this problem here, but I just wanted to bring this to light. A better solution is to define
AuthState
as an algebraic data type. Example:Describe the ideal solution
Replace
export type User = any;
defined inauth0-react/src/auth-state.tsx
Line 1 in 2ca701e
unknown
as at least this is typesafe.Alternatives and current work-arounds
One solution is to override / supersede the type definition of
User
in my own code.Additional context
None, other than I really like it when libraries use
unknown
instead ofany
. But regardless, thank you for your awesome open source library! 🙂The text was updated successfully, but these errors were encountered: