diff --git a/.changeset/clear-beds-refuse.md b/.changeset/clear-beds-refuse.md new file mode 100644 index 0000000..24316cb --- /dev/null +++ b/.changeset/clear-beds-refuse.md @@ -0,0 +1,5 @@ +--- +"react-polymorphic": patch +--- + +Fix `Inherit` required-prop behavior to preserve inherited `undefined` unions when converting optional inherited props to required. diff --git a/package.json b/package.json index 550641d..81e2c78 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-polymorphic", - "version": "1.0.1", + "version": "1.0.2", "description": "Create polymorphic React 19+ components with strong TypeScript inference.", "keywords": [ "react", diff --git a/src/createPolymorph.ts b/src/createPolymorph.ts index b3a52ae..1cd9a70 100644 --- a/src/createPolymorph.ts +++ b/src/createPolymorph.ts @@ -76,7 +76,7 @@ type RequiredKeys = { /** Sets all keys in `K` of type `T` to required. */ type Require = Overwrite< T, - Required> + { [P in Extract]: T[P] } >; // Tag ------------------------------------------------------------------------ diff --git a/tests/integrations/createPolymorph/config.test.tsx b/tests/integrations/createPolymorph/config.test.tsx index 6d34ff7..db06001 100644 --- a/tests/integrations/createPolymorph/config.test.tsx +++ b/tests/integrations/createPolymorph/config.test.tsx @@ -40,7 +40,7 @@ const ComponentE = createPolymorph< >(({ as: Tag = 'div', className, ...rest }) => { return ( ); diff --git a/tests/types/createPolymorph/Inherit.test.tsx b/tests/types/createPolymorph/Inherit.test.tsx index b738c89..71885c4 100644 --- a/tests/types/createPolymorph/Inherit.test.tsx +++ b/tests/types/createPolymorph/Inherit.test.tsx @@ -36,5 +36,6 @@ type _ = [ true > >, + Assert['onClick']>>, Assert, false>> ];