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.

Ability to exclude some chained prop types

See original GitHub issue

Is your feature request related to a problem? Please describe. I am trying to generate docs for a library and suddenly I got into a problem where I can’t exclude some inherited types (props) from TypeScript.

TypeScript types:

type ContentProps = {
  icon?: ReactNode | null;
  iconPosition?: string;
  children?: any;
};

export type Props = ButtonHTMLAttributes<HTMLButtonElement> &
  ContentProps & {
    buttonModifiers?: Array<string>;
    sizeType?: Size;
    style?: CSSProperties;
    className?: string;
    fullWidth?: boolean;
    fullHeight?: boolean;
  };

Button Component:

const Button = (props: Props) => ()

Describe the solution you’d like I want to be able to remove the props from HTMLButtonElement so it shows only the ContentProps and the other defined props (buttonModifiers,sizeType etc).

Describe alternatives you’ve considered None.

Are you able to assist bring the feature to reality? maybe …

Screenshot

Screenshot from 2020-04-09 21-39-29

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
shilmancommented, May 4, 2020

A workaround I’ve added is the ability to specify props include and exclude:

type PropDescriptor = string[] | RegExp;

interface BaseProps {
  include?: PropDescriptor;
  exclude?: PropDescriptor;
}

So you could achieve what you want by only including non-chained props. E.g.:

const include = ['buttonModifiers', 'sizeType', 'style', 'className', 'fullWidth', 'fullHeight'];

<Props of={Button} include={include} />;
1reaction
shilmancommented, Apr 12, 2020

@mustran Either 6.0, which should be stable by mid-May, or 6.1, which should be stable mid-Summer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Notes on TypeScript: Inferring React PropTypes
I think the problem in this specific case is tied to using forwardRef . Will try to find out in more detail ,...
Read more >
Typechecking With PropTypes - React
To run typechecking on the props for a component, you can assign the special propTypes property: import PropTypes from 'prop-types'; class Greeting extends ......
Read more >
Section 2: Excluding Props - React TypeScript Cheatsheets
The problem we want to solve is having the HOC-wrapped-component exposing a type that reflects the reduced surface area of props - without...
Read more >
You Might Not Need PropTypes in React - ITNEXT
In short, ARCcore Filter is similar to PropTypes except that it is a more general solution and data validation is performed in a...
Read more >
Inheritance and the prototype chain - JavaScript | MDN
We will discuss the prototype property of constructor functions in ... To use the new operator, call the function normally except prefix it ......
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