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(typings): unable to set many typical html element props #1072

Closed
dennari opened this issue Dec 21, 2016 · 13 comments
Closed

fix(typings): unable to set many typical html element props #1072

dennari opened this issue Dec 21, 2016 · 13 comments

Comments

@dennari
Copy link
Contributor

dennari commented Dec 21, 2016

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?

@dennari dennari changed the title Typings: unable to set id Typings: unable to set id Dec 21, 2016
@levithomason
Copy link
Member

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.

@asvetliakov
Copy link

asvetliakov commented Dec 21, 2016

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.

@levithomason
Copy link
Member

The 2) approach destroys parameter validation since you can pass anything.

Good point, this seems rather unfavorable.

@dennari
Copy link
Contributor Author

dennari commented Dec 21, 2016

The 2) approach destroys parameter validation since you can pass anything.

The validation still works as expected for the explicitly specified properties.

@asvetliakov
Copy link

Yes, seems i was wrong about 2. Latest compiler version works as expected.

@levithomason
Copy link
Member

levithomason commented Dec 22, 2016

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.

@levithomason
Copy link
Member

For clarity, we're ready for a community PR here implementing this pattern for all components:

interface SegmentProps {
  ...
  [key: string]: any;
}

@levithomason levithomason changed the title Typings: unable to set id Typings: unable to set many typical html element props Jan 9, 2017
@layershifter
Copy link
Member

layershifter commented Jan 13, 2017

TODO

@dstpierre
Copy link
Contributor

@levithomason I'm interested in completing this, can my PR contains all the component listed in the TODO above?

Thanks

@levithomason
Copy link
Member

@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.

@levithomason
Copy link
Member

@dstpierre looks like you're in a mad race with @layershifter for this one! 😉

@layershifter
Copy link
Member

It's done 😄

@levithomason
Copy link
Member

🎉 all praise be to you @layershifter, completely amazing work!

@levithomason levithomason changed the title Typings: unable to set many typical html element props fix(typings): unable to set many typical html element props Mar 1, 2017
@layershifter layershifter mentioned this issue Mar 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants