Skip to content

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

Merged
merged 7 commits into from
Aug 13, 2019

Conversation

emmenko
Copy link
Contributor

@emmenko emmenko commented Aug 13, 2019

Leftover of #1413

Fixes #1414

: T extends 'formatTime'
? FormatDateOptions
: FormatNumberOptions;

const displayNames: {
Copy link

@septs septs Aug 13, 2019

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"

Copy link
Contributor Author

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

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor Author

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 🤔

Copy link

@septs septs Aug 13, 2019

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];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting this error:

image

Copy link

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

Copy link
Contributor Author

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.

41d319f

@emmenko emmenko force-pushed the nm-fix-types-props branch from f0f4b78 to 8d78476 Compare August 13, 2019 07:15
@emmenko
Copy link
Contributor Author

emmenko commented Aug 13, 2019

@septs thanks for the feedback so far! Further improvements can be done as follow ups.

};

const Component = (props: Props) => (
Copy link

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

Copy link
Contributor Author

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? 🤔

Copy link

@septs septs Aug 13, 2019

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

Copy link
Member

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

Copy link
Contributor Author

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

image

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@longlho longlho left a 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) => (
Copy link
Member

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: {
Copy link
Member

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?

@longlho longlho merged commit 9b359ec into formatjs:master Aug 13, 2019
longlho pushed a commit that referenced this pull request Aug 30, 2019
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3.1.7 break compatibility
3 participants