Improve typing for "update" method on React useSession hook #9998
Benjamin-Richard-Carter
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Improve DX while using the "update" method of the useSession() hook, by enforcing type safety on the parameters
Background
Forgive me if I've misunderstood/overlooked something - I'm quite new to typescript and next-auth.
Currently the "update" method on the useSession hook is typed as such:
UpdateSession = (data?: any) => Promise<Session | null>
.Doing proper validation in the callback can prevent the adapter trying to run a query with incorrectly structured data, but as of now the developer receives no indication that there is an issue with the data provided to the method in their component, until an error is thrown at runtime when the data reaches the callback.
Proposal
In order to provide type checking and code completion on the "update" method during development, would it not be more appropriate to type the data parameter as such:
UpdateSession = (data?: Partial<Session>) => Promise<Session | null>
, thus immediately alerting the developer that the new session data being provided to the method does not satisfy the current Session schemaBeta Was this translation helpful? Give feedback.
All reactions