react-docgen-typescript icon indicating copy to clipboard operation
react-docgen-typescript copied to clipboard

Extending an existing prop interface with Omit type results in missing props.

Open juanfabrega opened this issue 3 years ago • 4 comments

We build a lot of components by extending some basic primitives and as such, most of our component prop interfaces begin by extending the props of those primitive components. For example:

interface ComponentProps extends PrimitiveProps {
  someNewProp: boolean;
}

const Component<ComponentProps> = ({ ...props }) => {
...component code here

this works really well and our prop tables in storybook get filled in with all the props just fine. However, in some cases we want to exclude some props from the primitive type. In these cases we've tried the Omit type.

type PrimitiveWithoutSomeProp = Omit<PrimitiveProps, 'someProp'>;
type ComponentProps = PrimitiveWithoutSomeProp & {
  someNewProp: boolean;
}

const Component<ComponentProps> = ({ ...props }) => {
...component code here

In these cases, all props coming from the primitive will disappear and my props table only shows the single component prop. Anybody else have this issue? Is there perhaps something we're doing wrong? Thanks!

juanfabrega avatar Mar 24 '21 18:03 juanfabrega

+1

PengJiyuan avatar Jul 13 '21 09:07 PengJiyuan

I'm seeing the same thing. Wonder why this is getting no replies...

bmmpt avatar Sep 21 '21 23:09 bmmpt

Have the same issue

ArthurStam avatar Oct 11 '21 14:10 ArthurStam

+1

ly-tc avatar Jul 30 '22 17:07 ly-tc

+1

courdek avatar Oct 28 '22 20:10 courdek

I figured out that when you are using the withCustomConfig function from react-docgen-typescript it also works using Omit or Pick on your PrimitiveProps. You can check the Readme for information on how to use it. I also set these options

withCustomConfig("tsconifg.json, {
savePropValueAsString: true,
shouldExtractLiteralValuesFromEnum: true,
propFilter: ...,
})

Cuzart avatar Oct 31 '22 07:10 Cuzart

There was no activity for a long time. The issue will be closed soon.

github-actions[bot] avatar Oct 31 '23 10:10 github-actions[bot]

Closing this issue as obsolete.

github-actions[bot] avatar Nov 07 '23 10:11 github-actions[bot]