Skip to content
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

fix(Divider|FormInput): fix the broken typings #1179

Merged

Conversation

dennari
Copy link
Contributor

@dennari dennari commented Jan 18, 2017

Fixes #1180.

@@ -173,7 +173,7 @@ interface FormGroupProps {

export const FormGroup: React.ComponentClass<FormGroupProps>;

interface FormInputProps extends InputProps, ReactFormEvents<HTMLInputElement>, ReactFocusEvents<HTMLInputElement> {
interface FormInputProps extends InputBaseProps, ReactFormEvents<HTMLInputElement>, ReactFocusEvents<HTMLInputElement> {
Copy link
Member

Choose a reason for hiding this comment

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

Hm, why exclude the onChange prop from the FormInputProps? All Input props are supported in the Form control shorthand components. I may be missing something here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the error I got before:

> tsc


176 interface FormInputProps extends InputProps, ReactFormEvents<HTMLInputElement>, ReactFocusEvents<HTMLInputElement> {
              ~~~~~~~~~~~~~~

node_modules/semantic-ui-react/dist/commonjs/collections/Form/index.d.ts(176,11): error TS2320: Interface 'FormInputProps' cannot simultaneously extend types 'InputProps' and 'ReactFormEvents<HTMLInputElement>'.
  Named property 'onChange' of types 'InputProps' and 'ReactFormEvents<HTMLInputElement>' are not identical.

So ReactFormEvents<HTMLInputElement> already includes the onChange prop with an incompatible signature. This is probably not the cleanest possible fix, but it works at least.

Copy link
Member

Choose a reason for hiding this comment

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

I think we can just remove ReactFormEvents<HTMLInputElement> and ReactFocusEvents<HTMLInputElement> there, because we don't expose non SUIR props (#1072).

Copy link
Member

Choose a reason for hiding this comment

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

The signature for this:

<Form.Input onChange={ ... } />

Should be identical to this:

<Input onChange={ ...  } />

Wihch is:

onChange(event: React.SyntheticEvent<HTMLInputElement>, data: InputOnChangeData) => void

So the onChange signature from ReactFormEvents<HTMLInputElement> is not correct for this case since it does not include the data argument. I'm not a ts user so I'm not exactly sure of the fix here, however, I wanted to note the actual signatures.

Copy link
Contributor

@rokoroku rokoroku Jan 20, 2017

Choose a reason for hiding this comment

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

How about adding
onChange, onInput, onSubmit methods to the InputProps and removing extend ReactFormEvents? (If these methods are available)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@layershifter's suggestion seems to me to be the correct one in this case

@codecov-io
Copy link

codecov-io commented Jan 18, 2017

Current coverage is 95.88% (diff: 100%)

Merging #1179 into master will not change coverage

@@             master      #1179   diff @@
==========================================
  Files           879        879          
  Lines          4888       4888          
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
  Hits           4687       4687          
  Misses          201        201          
  Partials          0          0          

Powered by Codecov. Last update 9fe3fca...11bc3fc

@@ -34,4 +34,4 @@ interface DividerProps {
vertical?: boolean;
}

export const Container: React.StatelessComponent<DividerProps>;
export const Divider: React.StatelessComponent<DividerProps>;
Copy link
Member

Choose a reason for hiding this comment

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

Thanks, copy-paste is evil.

@layershifter layershifter changed the title Fix the broken typings for FormInput and Divider fix(Divider|FormInput): fix the broken typings Jan 21, 2017
Copy link
Member

@layershifter layershifter left a comment

Choose a reason for hiding this comment

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

I've returned onChange on Input typings. LGTM, ready to merge 👍

@levithomason
Copy link
Member

Will this not throw the same error in FormInput about duplicate onChange props with different signatures?

@layershifter
Copy link
Member

@levithomason nope, problem was there:

(176,11): error TS2320: Interface 'FormInputProps' cannot simultaneously extend types 'InputProps' and 'ReactFormEvents<HTMLInputElement>'.
  Named property 'onChange' of types 'InputProps' and 'ReactFormEvents<HTMLInputElement>' are not identical.

FormInputProps extended InputProps and ReactFormEvents, while the last two have the same onChange method, but with different signatures. After changes in this PR, FormInputProps will extend only InputProps.

@bychwa
Copy link

bychwa commented Jan 23, 2017

Can someone merge this? Am stuck with this error! :-)

@levithomason levithomason merged commit 3b9c90b into Semantic-Org:master Jan 23, 2017
@levithomason
Copy link
Member

Released in [email protected].

DomiR added a commit to DomiR/Semantic-UI-React that referenced this pull request Jan 26, 2017
* Semantic-Org/master: (111 commits)
  fix(docs): fix usage of arrow function (Semantic-Org#1228)
  fix(Icon): Incorrect definition in typings (Semantic-Org#1225)
  fix(Button): fix `tabIndex` in typings (Semantic-Org#1224)
  fix(typings): add item prop to the DropdownProps (Semantic-Org#1223)
  docs(examples): add missing `key` props (Semantic-Org#1220)
  docs(changelog): update changelog [ci skip]
  0.64.4
  feat(Form): add `inverted` prop (Semantic-Org#1218)
  fix(ComponentExample): use explicit babel presets (Semantic-Org#1219)
  style(Button): update typings and propTypes usage (Semantic-Org#1216)
  style(Embed): update typings and propTypes usage (Semantic-Org#1217)
  chore(package): support for jsnext:main (Semantic-Org#1210)
  style(Step): update typings, tests and propTypes usage (Semantic-Org#1203)
  fix(Portal): do not take focus after first render (Semantic-Org#1215)
  style(Table|mixed): update typings, tests and propTypes usage (Semantic-Org#1200)
  fix(Dropdown): use `item` instead of `as={Menu.Item}` (Semantic-Org#659)
  fix(Dropdown): respect `closeOnBlur={false}` (Semantic-Org#1148)
  style(Breadcrumb): update typings and propTypes usage (Semantic-Org#1209)
  style(Dimmer): update typings (Semantic-Org#1208)
  fix(Divider|FormInput): fix the broken typings (Semantic-Org#1179)
  ...
harel pushed a commit to harel/Semantic-UI-React that referenced this pull request Feb 18, 2017
* Fix the broken typings for FormInput and Divider

* Typings: remove non SUIR props from FormIputProps and InputProps

* revert(Input): revert removing of `onChange`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants