Skip to content

Commit 926dc39

Browse files
wooormJounQin
andcommitted
Fix types to accept properties or child at once
Closes GH-24. Co-authored-by: JounQin <8336744+JounQin@users.noreply.github.com>
1 parent 1f7110f commit 926dc39

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

‎lib/create-h.js‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,8 @@ export function createH(schema, defaultTagName, caseSensitive) {
9292
* @overload
9393
* @param {string} selector
9494
* Selector.
95-
* @param {Properties} properties
96-
* Properties.
97-
* @param {...Child} children
98-
* Children.
99-
* @returns {Element}
100-
* Element.
101-
*
102-
* @overload
103-
* @param {string} selector
104-
* Selector.
95+
* @param {Child | Properties | null | undefined} [properties]
96+
* Properties (or first child) (default: `undefined`).
10597
* @param {...Child} children
10698
* Children.
10799
* @returns {Element}

‎test-d/index.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ expectType<Element>(h('', {p: {x: 1}})) // Style
4545
// @ts-expect-error: not a property value.
4646
h('', {p: {x: true}})
4747

48+
declare const propertiesOrNullish: Record<string, string> | null | undefined
49+
expectType<Element>(h('', propertiesOrNullish))
50+
expectType<Element>(h('', propertiesOrNullish, 'a'))
51+
declare const propertiesOrChild: Record<string, string> | string
52+
expectType<Element>(h('', propertiesOrChild))
53+
expectType<Element>(s('', propertiesOrChild))
54+
4855
expectType<Element>(
4956
s('svg', {viewbox: '0 0 500 500', xmlns: 'http://www.w3.org/2000/svg'}, [
5057
s('title', 'SVG `<circle` element'),

0 commit comments

Comments
 (0)