Skip to content

Commit eb2d0c2

Browse files
authored
fix(jsx): widen jsx and jsxFn children to Child[] (#4947)
1 parent dcabbec commit eb2d0c2

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

src/jsx/base.test.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @jsxImportSource ./ */
22

3-
import type { JSXNode } from './base'
3+
import type { Child, JSXNode } from './base'
44
// eslint-disable-next-line @typescript-eslint/no-unused-vars
55
import { cloneElement, jsx, Fragment } from './base'
66

@@ -43,4 +43,10 @@ describe('createElement', () => {
4343
expect(element.type).toBe('svg')
4444
expect(element.ref).toBe(ref)
4545
})
46+
47+
it('should accept a Child-typed value as a child', () => {
48+
const child: Child = <span>inner</span>
49+
const element = jsx('div', null, child) as unknown as JSXNode
50+
expect(element.toString()).toBe('<div><span>inner</span></div>')
51+
})
4652
})

src/jsx/base.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,7 @@ export class JSXFragmentNode extends JSXNode {
302302
}
303303
}
304304

305-
export const jsx = (
306-
tag: string | Function,
307-
props: Props | null,
308-
...children: (string | number | HtmlEscapedString)[]
309-
): JSXNode => {
305+
export const jsx = (tag: string | Function, props: Props | null, ...children: Child[]): JSXNode => {
310306
props ??= {}
311307
if (children.length) {
312308
props.children = children.length === 1 ? children[0] : children
@@ -321,11 +317,7 @@ export const jsx = (
321317
}
322318

323319
let initDomRenderer = false
324-
export const jsxFn = (
325-
tag: string | Function,
326-
props: Props,
327-
children: (string | number | HtmlEscapedString)[]
328-
): JSXNode => {
320+
export const jsxFn = (tag: string | Function, props: Props, children: Child[]): JSXNode => {
329321
if (!initDomRenderer) {
330322
for (const k in domRenderers) {
331323
// eslint-disable-next-line @typescript-eslint/no-explicit-any

0 commit comments

Comments
 (0)