I was running in to problems trying to set the id attribute for Segment. Currently the typings don't allow this in TSX, even if it would be perfectly ok in JSX. The same is true for a number of other standard html attributes and Semantic-UI-React-Components.
One option would be to change
interface SegmentProps {
to
interface SegmentProps extends React.HTMLProps<HTMLElement> {
giving the ability to set a huge amount of additional attributes, including id. This however floods the intellisense with attributes that are probably unneeded 95% of the time.
Another option would be to add an index type:
interface SegmentProps {
...
[key: string]: any;
}
which would then allow any property to be set without flooding intellisense.
Any thoughts?
I would assume the latter would be more useful to users. That said, I'd like to get some feedback on this from our ts users before merging a fix.
/cc @tomitrescak @hlehmann @JasonRitchie @garyham @asvetliakov @halfmatthalfcat @psudarsa
You all have been active in our ts decisions in the past, let us know your thoughts here.
For now you can use module augmentation i think
declare module "semantic-ui-react" {
interface SegmentProps {
id?: string;
}
// or
interface SegmentProps extends React.HTMLProps<HTMLElement> {}
}
Personally i'm doing 1) approach for elements where passing html attributes does make sense (input, form, etc...)
The 2) approach destroys parameter validation since you can pass anything.
The 2) approach destroys parameter validation since you can pass anything.
Good point, this seems rather unfavorable.
The 2) approach destroys parameter validation since you can pass anything.
The validation still works as expected for the explicitly specified properties.
Yes, seems i was wrong about 2. Latest compiler version works as expected.
If there is an agreement on 2, I'd merge a PR for that. It would be nice _not_ to have the common HTML props flooding the completions. I think the intent is for users to see the custom component props.
For clarity, we're ready for a community PR here implementing this pattern for all components:
interface SegmentProps {
...
[key: string]: any;
}
@levithomason I'm interested in completing this, can my PR contains all the component listed in the TODO above?
Thanks
@dstpierre awesome! I'd prefer we do only a few at a time. It is easier to review and manage conflicts that way. Also, anytime there is a list of items todo like this, there always seems to be other small bug fixes and updates that are necessary along the way. Keeping the PRs small keeps the changes manageable, whereas, grouping them tends to lead to a massive PR that has a very hard time getting merged.
@dstpierre looks like you're in a mad race with @layershifter for this one! 馃槈
It's done 馃槃
馃帀 all praise be to you @layershifter, completely amazing work!