@@ -6,10 +6,6 @@ type HTMLElementConstructor = typeof HTMLElement
66
77type HTMLElementType < T extends HTMLElementConstructor > = T [ 'prototype' ]
88
9- type HTMLElementsTypes < T extends Record < string , HTMLElementConstructor > > = {
10- [ K in keyof T ] : HTMLElementType < T [ K ] >
11- }
12-
139type BuiltInType = Number | String | Array < any > | Object | Boolean
1410
1511type BuiltInTypeConstructor =
@@ -27,7 +23,7 @@ type PropTypes<Definitions extends SimpleComponentOptions['props']> = {
2723 : Definitions [ K ]
2824}
2925
30- export type SimpleRefs = Record < string , HTMLElement >
26+ export type SimpleRefs = Record < string , HTMLElement | SimpleElement < any > >
3127
3228export type SimpleRefsAll < R extends SimpleRefs = any > = {
3329 [ K in keyof R ] : R [ K ] [ ]
@@ -36,13 +32,21 @@ export type SimpleRefsAll<R extends SimpleRefs = any> = {
3632export interface SimpleComponentOptions {
3733 el ?: HTMLElementConstructor
3834 props ?: Record < string , BuiltInType | BuiltInTypeConstructor >
39- refs ?: Record < string , HTMLElementConstructor >
35+ refs ?: Record < string , HTMLElementConstructor | SimpleComponent >
4036 events ?: Record < string , any >
4137}
4238
39+ type ResolveRefs < Refs extends SimpleComponentOptions [ 'refs' ] > = {
40+ [ K in keyof Refs ] : Refs [ K ] extends HTMLElementConstructor
41+ ? HTMLElementType < Refs [ K ] >
42+ : Refs [ K ] extends SimpleComponent
43+ ? SimpleElement < Refs [ K ] >
44+ : never
45+ }
46+
4347export type SimpleComponentContext <
4448 Options extends SimpleComponentOptions ,
45- Refs extends SimpleRefs = HTMLElementsTypes < NonNullable < Options [ 'refs' ] > >
49+ Refs extends SimpleRefs = ResolveRefs < NonNullable < Options [ 'refs' ] > >
4650> = {
4751 el : Options [ 'el' ] extends HTMLElementConstructor
4852 ? HTMLElementType < Options [ 'el' ] >
@@ -115,3 +119,7 @@ export type SimpleElement<
115119 $refsAll : Context [ 'refsAll' ]
116120 $props : Context [ 'props' ]
117121} & Context [ 'el' ]
122+
123+ const el = document . createElement ( 'div' )
124+
125+ type T = typeof el
0 commit comments