-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
fix(Divider|FormInput): fix the broken typings #1179
Conversation
@@ -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> { |
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.
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.
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.
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.
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.
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.
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.
How about adding
onChange
, onInput
, onSubmit
methods to the InputProps
and removing extend ReactFormEvents
? (If these methods are available)
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.
@layershifter's suggestion seems to me to be the correct one in this case
Current coverage is 95.88% (diff: 100%)@@ 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
|
@@ -34,4 +34,4 @@ interface DividerProps { | |||
vertical?: boolean; | |||
} | |||
|
|||
export const Container: React.StatelessComponent<DividerProps>; | |||
export const Divider: React.StatelessComponent<DividerProps>; |
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, copy-paste is evil.
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 returned onChange
on Input
typings. LGTM, ready to merge 👍
Will this not throw the same error in FormInput about duplicate onChange props with different signatures? |
@levithomason nope, problem was there:
|
Can someone merge this? Am stuck with this error! :-) |
Released in |
* 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) ...
* Fix the broken typings for FormInput and Divider * Typings: remove non SUIR props from FormIputProps and InputProps * revert(Input): revert removing of `onChange`
Fixes #1180.