@@ -13,7 +13,7 @@ import {bindChildren, bindProps} from "./utils"
13
13
// TODO: make children optional
14
14
export type FunctionComponent <
15
15
Props extends { } | null | undefined ,
16
- Children extends ChildrenType = ChildrenType ,
16
+ Children extends unknown [ ] = ChildrenType ,
17
17
Returns extends Node | JSX . Element = JSX . Element ,
18
18
> = ( props : Props , ...children : Children ) => Returns
19
19
@@ -130,32 +130,15 @@ export function createElement(
130
130
* @throws {Error } - If `tagNameOrFunction` is not a string or function, an errow is thrown
131
131
*/
132
132
export function createElement <
133
- Props extends { } | null | undefined ,
134
- Children extends ChildrenType ,
135
- Returns extends Node | JSX . Element ,
136
- > (
137
- func : FunctionComponent < Props , Children , Returns > ,
138
- props ?: Props | null ,
139
- ...children : Children
140
- ) : Returns
141
-
142
- /**
143
- * Creates a function component
144
- *
145
- * @param func - Function component
146
- * @param props - Props of function component
147
- * @param children - Children of this element. Can be nothing, number, string, boolean, bigint, or
148
- * more elements. An array will create multiple, flattened children.
149
- * @returns Element
150
- * @throws {Error } - If `tagNameOrFunction` is not a string or function, an errow is thrown
151
- */
152
- export function createElement <
153
- Props extends { } | null | undefined ,
133
+ Props extends { } | null ,
134
+ Children extends unknown [ ] ,
154
135
Returns extends Node | JSX . Element ,
155
136
> (
156
- func : FunctionComponent < Props , ChildrenType , Returns > ,
157
- props ?: Props | null ,
158
- ...children : ChildrenType
137
+ ...[ func , props , ...children ] : [
138
+ func : FunctionComponent < Props , Children , Returns > ,
139
+ ...( Props extends null ? [ props ?: Props | undefined ] : [ props : Props ] ) ,
140
+ ...children : Children ,
141
+ ]
159
142
) : Returns
160
143
161
144
/**
@@ -170,12 +153,9 @@ export function createElement<
170
153
* @returns Element
171
154
* @throws {Error } - If `tagNameOrFunction` is not a string or function, an errow is thrown
172
155
*/
173
- export function createElement <
174
- T extends string | { [ key : string ] : unknown } | null | undefined ,
175
- Returns = void ,
176
- > (
156
+ export function createElement < T extends string | { [ key : string ] : unknown } | null , Returns = void > (
177
157
tagNameOrFunction : T | ( ( _props : T , ..._children : ChildrenType ) => Returns ) ,
178
- props ?: HTMLElementProps [ T extends string ? T : "" ] | null | T ,
158
+ props ?: HTMLElementProps [ T extends string ? T : "" ] | null | T | undefined ,
179
159
...children : ChildrenType
180
160
) : Element | Returns {
181
161
if ( typeof tagNameOrFunction === "string" ) {
@@ -198,7 +178,7 @@ export function createElement<
198
178
} else if ( typeof tagNameOrFunction === "function" ) {
199
179
// If `tagNameOrFunction` is a function, then the previous overload should've enforced that
200
180
// the props are set by the function (`T`)
201
- return tagNameOrFunction ( props as T , children )
181
+ return tagNameOrFunction ( ( props ?? null ) as T , children )
202
182
}
203
183
204
184
throw new Error ( `Invalid element type ${ typeof tagNameOrFunction } : ${ tagNameOrFunction } ` )
0 commit comments