diff --git a/src/index.ts b/src/index.ts index e315482..a865591 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,7 +11,8 @@ export function propose< OriginalProps extends ComponentProps, SuppliedProps extends Partial >(Component: ComponentType, props: SuppliedProps, displayName?: string) { - type FinalProps = Omit & Partial; + type FinalProps = Omit & + Partial; const NewComponent: React.FC = (p) => { const combinedProps = { ...props, ...p }; diff --git a/src/propose.test.tsx b/src/propose.test.tsx index 1273129..da89181 100644 --- a/src/propose.test.tsx +++ b/src/propose.test.tsx @@ -11,6 +11,7 @@ describe('propose', () => { const Decorated = propose(Base, { message: 'hello, world' }, 'Decorated'); expect(Decorated.displayName).toBe('Decorated'); }); + it('renders correctly', () => { const Base: React.FC<{ message: string; title?: string }> = ({ message, @@ -52,4 +53,24 @@ describe('propose', () => { const { getByRole } = render(); expect(getByRole('heading')).toHaveTextContent('Foo'); }); + + it('respects inherited props', () => { + interface SharedLinkProps { + variant: 'primary' | 'secondary'; + } + interface LinkButtonProps + extends SharedLinkProps, + Pick< + React.DetailedHTMLProps< + React.ButtonHTMLAttributes, + HTMLButtonElement + >, + 'onClick' + > {} + + const Base: React.FC = () =>
; + + const Derived = propose(Base, { variant: 'primary' }); + render( {}} variant="primary" />); + }); });