-
Notifications
You must be signed in to change notification settings - Fork 59
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
feat: 🎸 improve yar values and flash typings #169
base: master
Are you sure you want to change the base?
Conversation
damusix
commented
Mar 19, 2024
- This is a proposition to enforce yar typings
- Increases visibility into session data
- Enforces consistent flash types
0c7bbb3
to
02839f6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My suggestions seem to fix the export error while still passing the tests. I think we should include error tests to make sure types are just what they pretend to be
02839f6
to
418495f
Compare
ready now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While it makes sense to more strictly type the entries, this approach seems too simple/broken.
Eg. the new generics are pointless since any override must extend from YarValues
/YarFlashes
. It's not possible to do request.yar.get<{ a: string }>('a')
if other custom properties have been added to YarValues
.
I'm also missing tests around how set(object)
handles errors. Does it even error, or will it accept any object? There are multiple interesting cases here. Also, it would be nice if expect.type()
was used to validate the returned types.
Thank you for the feedback it was very insightful. You actually unblocked my though process given what you alluded to about |
|
@@ -109,20 +117,26 @@ declare namespace yar { | |||
/** | |||
* - assigns a value (string, object, etc) to a given key which will persist across requests. Returns the value. | |||
*/ | |||
set<T>(key: string, value: T): T; | |||
set<T extends YarValKeys>(key: T, value: YarValues[T]): YarValues[T]; | |||
set<T = unknown>(key: string, value: T): T; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR looks all right, why did you need all those declarations with unknown though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Marsup this allowed the autocomplete to pick up <T extends YarValKeys>(key: T, value: YarValues[T])
as well as (key: string, value: T)
, allowing for typed yar values, and also unknown values. Without the <T = unknown>
, it wouldn't pick up any types and set values to any
. This was the "AHAH!" moment from @kanongil 's comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I tend to avoid overloads whenever possible as it makes manipulating types much harder, if there's no other way 🤷🏻♂️
@kanongil does it address your concerns properly? |
@kanongil Mind lending a follow up? This would be cool to be able to use. |