Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/early-llamas-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@devup-ui/react": patch
---

divide children prop in props prop
38 changes: 37 additions & 1 deletion packages/react/src/types/props/__tests__/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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<DevupComponentAdditionalProps<typeof Foo>>({
props: { c: 'a' },
})

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function Bar({ children: _ }: { children: string; c: string }) {
return null
}
assertType<DevupComponentAdditionalProps<typeof Bar>>({
props: { c: 'a' },
children: 'b',
})

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function Baz({ children: _ }: { children?: string; c?: string }) {
return null
}
assertType<DevupComponentAdditionalProps<typeof Baz>>({
props: { c: 'a' },
children: 'b',
})
assertType<DevupComponentAdditionalProps<typeof Baz>>({})
assertType<DevupComponentAdditionalProps<typeof Baz>>({
children: 'b',
})
})
})
22 changes: 16 additions & 6 deletions packages/react/src/types/props/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,21 @@ export type DevupElementTypeProps<T extends React.ElementType> =
export type DevupComponentAdditionalProps<
T extends React.ElementType,
P extends React.ComponentProps<T> = React.ComponentProps<T>,
> =
Partial<P> extends P
> = (Partial<P> extends P
? {
props?: FilterChildren<P>
}
: {
props: FilterChildren<P>
}) &
(P extends { children: infer U }
? {
props?: P
}
: {
props: P
children: U
}
: P extends { children?: infer U }
? {
children?: U
}
: object)

type FilterChildren<T> = Omit<T, 'children'>