question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
levithomasoncommented, Feb 22, 2017

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

1reaction
levithomasoncommented, Jan 17, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extending HTML elements in React and TypeScript while ...
I always use React.ComponentsProps<"button"> the generic input can be anything from a react component to a string such as "div". There are also ......
Read more >
Separate HTML attributes from styling props #439 - GitHub
I am trying to style a 3rd party "masked" input. The styles are applied correctly, however, there are props I pass into the...
Read more >
Useful Patterns by Use Case - React TypeScript Cheatsheets
Wrapping/Mirroring a HTML Element​. Usecase: you want to make a <Button> that takes all the normal props of <button> and does extra stuff ......
Read more >
Build strongly typed polymorphic components with React and ...
Learn how to build strongly typed polymorphic React components with TypeScript, using familiar Chakra UI and MUI component props as guides.
Read more >
How To Customize React Components with Props
In this tutorial, you'll create custom components by passing props to your component. Props are arguments that you provide to a JSX element....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found