diff --git a/.changeset/early-llamas-cross.md b/.changeset/early-llamas-cross.md new file mode 100644 index 00000000..36f0f526 --- /dev/null +++ b/.changeset/early-llamas-cross.md @@ -0,0 +1,5 @@ +--- +"@devup-ui/react": patch +--- + +divide children prop in props prop diff --git a/packages/react/src/types/props/__tests__/index.test-d.ts b/packages/react/src/types/props/__tests__/index.test-d.ts index 89c049e1..c29f29ce 100644 --- a/packages/react/src/types/props/__tests__/index.test-d.ts +++ b/packages/react/src/types/props/__tests__/index.test-d.ts @@ -1,7 +1,12 @@ import { Property } from 'csstype' import type { ResponsiveValue } from '../../responsive-value' -import type { DevupCommonProps, DevupComponentProps, DevupProps } from '..' +import type { + DevupCommonProps, + DevupComponentAdditionalProps, + DevupComponentProps, + DevupProps, +} from '..' import type { Selectors } from '../selector' describe('index', () => { @@ -103,4 +108,35 @@ describe('index', () => { `, }) }) + it('DevupComponentAdditionalProps', () => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + function Foo({ children: _ }: { children?: string; c: string }) { + return null + } + assertType>({ + props: { c: 'a' }, + }) + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + function Bar({ children: _ }: { children: string; c: string }) { + return null + } + assertType>({ + props: { c: 'a' }, + children: 'b', + }) + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + function Baz({ children: _ }: { children?: string; c?: string }) { + return null + } + assertType>({ + props: { c: 'a' }, + children: 'b', + }) + assertType>({}) + assertType>({ + children: 'b', + }) + }) }) diff --git a/packages/react/src/types/props/index.ts b/packages/react/src/types/props/index.ts index 9d1c13bb..9c6e486f 100644 --- a/packages/react/src/types/props/index.ts +++ b/packages/react/src/types/props/index.ts @@ -53,11 +53,21 @@ export type DevupElementTypeProps = export type DevupComponentAdditionalProps< T extends React.ElementType, P extends React.ComponentProps = React.ComponentProps, -> = - Partial

extends P +> = (Partial

extends P + ? { + props?: FilterChildren

+ } + : { + props: FilterChildren

+ }) & + (P extends { children: infer U } ? { - props?: P - } - : { - props: P + children: U } + : P extends { children?: infer U } + ? { + children?: U + } + : object) + +type FilterChildren = Omit