-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix: remove injectIntl types from component props #1415
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
Conversation
: T extends 'formatTime' | ||
? FormatDateOptions | ||
: FormatNumberOptions; | ||
|
||
const displayNames: { |
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.
enum DisplayName {
formatDate = 'FormattedDate',
formatTime = 'FormattedTime',
formatNumber = 'FormattedNumber',
}
DisplayName['formatDate'] // the value is "FormattedDate"
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 would personally avoid using enums
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.
why?
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.
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.
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.
Hmm sorry, I'm not sure I understand what you need me to do here 🤔
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.
const enum DisplayName {
formatDate = 'FormattedDate',
formatTime = 'FormattedTime',
formatNumber = 'FormattedNumber',
}
in component:
Component.displayName = DisplayName[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.
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.
replace const enum
to enum
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.
Ah thanks, I never used enum
so my knowledge of it is a bit limited.
f0f4b78
to
8d78476
Compare
@septs thanks for the feedback so far! Further improvements can be done as follow ups. |
}; | ||
|
||
const Component = (props: Props) => ( |
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.
#1416 not use any then
const Component: React.FC<Props> = (props) => {
// ... code ...
}
React.FC
definition: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/981cc6d51eb213943a3606c14ad75d65ea6b360f/types/react/index.d.ts#L493-L501
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.
Hmm what issue should this solve exactly? Also, can you explain how using React.FC
is different from props: Props
? 🤔
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.
expand React.FC<Props>
definition
get (props: Props, context?: any) => React.ReactElement | null
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.
yeah const Component: React.FC<Props> = props =>
gives u the correct type definition
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.
Just to clarify, what do you mean by the correct type definition
?
Using props: Props
is not wrong, this is also what you find in the TS docs
I'm also not against using React.FC
if you want to, I just want to understand what are the benefits of using that compared to props: Props
.
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.
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.
overall LGTM
}; | ||
|
||
const Component = (props: Props) => ( |
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.
yeah const Component: React.FC<Props> = props =>
gives u the correct type definition
: T extends 'formatTime' | ||
? FormatDateOptions | ||
: FormatNumberOptions; | ||
|
||
const displayNames: { |
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.
const enum
would work here I believe?
* fix: remove unused WrappedComponentProps type * refactor: don't use HOC for formatted component factory * refactor: simplify types interface * refactor: simplify code * refactor: simplify code * refactor: keep using React.FC * refactor: to use enum for DisplayName options fixes #1414
Leftover of #1413
Fixes #1414