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.

TypeScript: MenuItem does not allow the props needed by a component override

See original GitHub issue

CodeSandbox: https://codesandbox.io/s/chakra-ts-starter-s8bur

I came across this when trying to make a TypeScript sandbox for #142.

I think the type should allow the props allowed by the component used in the as prop. I appreciate this might be a little bit hard to do with TypeScript. I imagine some fun with generics is needed.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
aaronmcadamcommented, Oct 3, 2019

I don’t think that workaround is too bad.

I think we’d have to use generics, so it’d look something like this:

// when TypeScript 3.7 is out, we'll have recursive types.
// Some other wrapper type might work though
// `IconButtonProps` replaces `TComponentOverrideProps` here
type MenuButtonProps<TComponentOverrideProps> = MenuButtonProps & TComponentOverrideProps;

// then, using it in TSX would look like this:
<MenuButton<IconButtonProps> as={IconButton}>...</MenuButton>

Ref: https://mariusschulz.com/blog/passing-generics-to-jsx-elements-in-typescript

Formik allows users to use them to pass the type of form data: https://github.com/jaredpalmer/formik/issues/1694

0reactions
stale[bot]commented, Dec 9, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extend material-ui component in typescript - Stack Overflow
And I get this error for no overload match which is obvious because material ui Button component doesn't know about the "fontSize" new...
Read more >
MenuItem API - Material UI - MUI
Name Type Default autoFocus bool false children node classes object
Read more >
Override or set property to React element - DEV Community ‍ ‍
We will build a popup menu with a list of actions. The consumer will only add regular button or anchor elements as children...
Read more >
Codegen Guide: Components | Learn Plasmic
The override props allow you to customize this tree of elements exactly as you see fit to make your component come alive. You...
Read more >
Input Components - React-admin - Marmelab
Tip: If your interface has to support multiple languages, don't use the label prop. Provide one label per locale based on the default...
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