@@ -26,20 +26,21 @@ export type ComponentWithAs<T extends ValidComponent, Props = Record<never, neve
26
26
Assign < Assign < ComponentProps < T > , Props > , { as ?: ElementType } >
27
27
>
28
28
29
- export type HTMLPolymorphicComponents = {
30
- [ Tag in DOMElements ] : ComponentWithAs < Tag >
29
+ export type HTMLPolymorphicComponents <
30
+ Props extends Record < string , unknown > = Record < never , never > ,
31
+ > = {
32
+ [ Tag in DOMElements ] : ComponentWithAs < Tag , Props >
31
33
}
32
34
33
35
export type HTMLPolymorphicProps < T extends ElementType > = Omit < ComponentProps < T > , 'ref' > & {
34
36
as ?: ElementType
35
37
}
36
38
37
- type PolymorphFactory = {
38
- <
39
- T extends ElementType ,
40
- P extends Record < string , unknown > = Record < never , never > ,
41
- Options = never ,
42
- > (
39
+ type PolymorphFactory <
40
+ Props extends Record < string , unknown > = Record < never , never > ,
41
+ Options = never ,
42
+ > = {
43
+ < T extends ElementType , P extends Record < string , unknown > = Props > (
43
44
component : T ,
44
45
option ?: Options ,
45
46
) : ComponentWithAs < T , P >
@@ -74,9 +75,9 @@ interface PolyFactoryParam<
74
75
* <poly.section as="main" /> => // renders main
75
76
*/
76
77
export function polymorphicFactory <
77
- Component extends ElementType ,
78
- Props extends Record < string , unknown > ,
78
+ Props extends Record < never , never > ,
79
79
Options = never ,
80
+ Component extends ElementType = ElementType ,
80
81
> ( { styled = defaultStyled } : PolyFactoryParam < Component , Props , Options > = { } ) {
81
82
const cache = new Map < Component , ComponentWithAs < Component , Props > > ( )
82
83
@@ -100,5 +101,5 @@ export function polymorphicFactory<
100
101
}
101
102
return cache . get ( asElement )
102
103
} ,
103
- } ) as PolymorphFactory & HTMLPolymorphicComponents
104
+ } ) as PolymorphFactory < Props , Options > & HTMLPolymorphicComponents < Props >
104
105
}
0 commit comments