Skip to content

Commit 48f9c70

Browse files
authored
Merge pull request #379 from dev-five-git/as-with-children
As with children
2 parents c046197 + 13d40e3 commit 48f9c70

File tree

3 files changed

+58
-7
lines changed

3 files changed

+58
-7
lines changed

.changeset/early-llamas-cross.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@devup-ui/react": patch
3+
---
4+
5+
divide children prop in props prop

packages/react/src/types/props/__tests__/index.test-d.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { Property } from 'csstype'
22

33
import type { ResponsiveValue } from '../../responsive-value'
4-
import type { DevupCommonProps, DevupComponentProps, DevupProps } from '..'
4+
import type {
5+
DevupCommonProps,
6+
DevupComponentAdditionalProps,
7+
DevupComponentProps,
8+
DevupProps,
9+
} from '..'
510
import type { Selectors } from '../selector'
611

712
describe('index', () => {
@@ -103,4 +108,35 @@ describe('index', () => {
103108
`,
104109
})
105110
})
111+
it('DevupComponentAdditionalProps', () => {
112+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
113+
function Foo({ children: _ }: { children?: string; c: string }) {
114+
return null
115+
}
116+
assertType<DevupComponentAdditionalProps<typeof Foo>>({
117+
props: { c: 'a' },
118+
})
119+
120+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
121+
function Bar({ children: _ }: { children: string; c: string }) {
122+
return null
123+
}
124+
assertType<DevupComponentAdditionalProps<typeof Bar>>({
125+
props: { c: 'a' },
126+
children: 'b',
127+
})
128+
129+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
130+
function Baz({ children: _ }: { children?: string; c?: string }) {
131+
return null
132+
}
133+
assertType<DevupComponentAdditionalProps<typeof Baz>>({
134+
props: { c: 'a' },
135+
children: 'b',
136+
})
137+
assertType<DevupComponentAdditionalProps<typeof Baz>>({})
138+
assertType<DevupComponentAdditionalProps<typeof Baz>>({
139+
children: 'b',
140+
})
141+
})
106142
})

packages/react/src/types/props/index.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,21 @@ export type DevupElementTypeProps<T extends React.ElementType> =
5353
export type DevupComponentAdditionalProps<
5454
T extends React.ElementType,
5555
P extends React.ComponentProps<T> = React.ComponentProps<T>,
56-
> =
57-
Partial<P> extends P
56+
> = (Partial<P> extends P
57+
? {
58+
props?: FilterChildren<P>
59+
}
60+
: {
61+
props: FilterChildren<P>
62+
}) &
63+
(P extends { children: infer U }
5864
? {
59-
props?: P
60-
}
61-
: {
62-
props: P
65+
children: U
6366
}
67+
: P extends { children?: infer U }
68+
? {
69+
children?: U
70+
}
71+
: object)
72+
73+
type FilterChildren<T> = Omit<T, 'children'>

0 commit comments

Comments
 (0)