-
Notifications
You must be signed in to change notification settings - Fork 734
Migrate Badge to TS #937
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
Migrate Badge to TS #937
Conversation
src/components/badge/index.tsx
Outdated
type LabelFormatterValues = typeof LABEL_FORMATTER_VALUES[number] | ||
export type BadgeSizes = keyof typeof BADGE_SIZES | ||
|
||
export type BadgePropTypes = ViewProps & TouchableOpacityProps & { |
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.
Let's keep the name as BadgeProp
instead of BadgePropTypes
, I wanted to have a shorter name
(I know we already have some components with xxxPropTypes, we'll change them eventually).
/** | ||
* the badge size (default, small) | ||
*/ | ||
size: BadgeSizes | number; |
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.
Should it be optional as the rest of the props?
Otherwise it will require user to pass it (even though it has a default value)
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've checked the example screen and it doesn't require since it knows to use the defaultProp
(I left some examples where size is not passed).
As far as I know this is the only way to make TS take into account defaultProps
:
size: 'default'
.
Also, TS doesn't like it as optional, it yells at me for methods that use size
and assume that it can be undefined and fall back to defaultProp
.
Same thing we did in Avatar btw: https://github.com/wix/react-native-ui-lib/blob/master/src/components/avatar/index.tsx#L121
WOAUILIB-1070