-
Notifications
You must be signed in to change notification settings - Fork 82
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
refactor: Improve typing so it shows the props #1591
Conversation
✔️ Deploy Preview for forma-36 ready! 🔨 Explore the source changes: 751e39d 🔍 Inspect the deploy log: https://app.netlify.com/sites/forma-36/deploys/61b0ea9a02e4c30007accdee 😎 Browse the preview: https://deploy-preview-1591--forma-36.netlify.app |
@@ -1,5 +1,11 @@ | |||
import React from 'react'; | |||
|
|||
export type ExpandProps<T> = T extends object |
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.
Wow, this is quite cool. Now I need to understand how it works :)
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.
What this does is get the type T
and if it's an object, it creates a copy and iterate over and returns a object typing {}
, so it shows up as that on the definition not as the name.
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.
thanks for the explanation
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.
Could you add some explanation around this type in the code comment, like the purpose and how it works (pretty much your answer for Alex) for the future us.
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.
+1 ☝️
import getStyles from './ButtonGroup.styles'; | ||
import type { ButtonGroupProps } from './types'; | ||
|
||
function _ButtonGroup(props: ButtonGroupProps, ref: React.Ref<HTMLDivElement>) { | ||
function _ButtonGroup( | ||
props: ExpandProps<ButtonGroupProps>, |
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.
can ExpandProps be a part of ButtonGroupProps?
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.
Sadly no, because it would expand the Type inside the ButtonGroupProps
, but here it would show as ButtonGroupProps
only, and not the values inside it
This is so much better 😍 |
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.
I think it's an obvious improvement compared to what we currently have, so let's go for it.
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.
Much better for user experience 👍
And codewise, I think, it's alright. Our polymorphic types are already a pretty magical thing, it won't make it worse 😄
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.
100% an improvement!
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.
🧙
@@ -1,5 +1,11 @@ | |||
import React from 'react'; | |||
|
|||
export type ExpandProps<T> = T extends object |
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.
+1 ☝️
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.
💪🧙♂️ Great improvement! ❤️ it!
Before
With these changes instead of the IDE showing:
After
It will expand the props and show like this:
Currently I'm checking if it's possible to get rid of then more
and show all of them, but seems like a configuration on the editor sideIt's actually on the tsserver file used on the VSCode, it isn't even a configuration that can be changed by the user without changing the file itself, for more context check here
PS: Only did the changes on the Button package for now, while I'm checking how to get that improved.
PS2: If you try this branch locally you may need to rebuild the packages and maybe restart the TS server.