File tree Expand file tree Collapse file tree 3 files changed +58
-7
lines changed
packages/react/src/types/props Expand file tree Collapse file tree 3 files changed +58
-7
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @devup-ui/react " : patch
3+ ---
4+
5+ divide children prop in props prop
Original file line number Diff line number Diff line change 11import { Property } from 'csstype'
22
33import 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 '..'
510import type { Selectors } from '../selector'
611
712describe ( '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} )
Original file line number Diff line number Diff line change @@ -53,11 +53,21 @@ export type DevupElementTypeProps<T extends React.ElementType> =
5353export 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' >
You can’t perform that action at this time.
0 commit comments