-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathindex.ts
More file actions
61 lines (55 loc) · 1.83 KB
/
index.ts
File metadata and controls
61 lines (55 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import {Fragment, jsxs, jsx} from 'hastscript/jsx-runtime'
import {h, s} from 'hastscript'
import type {Element, Root} from 'hast'
import {expectType} from 'tsd'
expectType<Root>(jsx(Fragment, {}))
expectType<Root>(jsx(Fragment, {children: h('h')}))
expectType<Element>(jsx('a', {}))
expectType<Element>(jsx('a', {children: 'a'}))
expectType<Element>(jsx('a', {children: h('h')}))
expectType<Element>(jsxs('a', {children: ['a', 'b']}))
expectType<Element>(jsxs('a', {children: [h('x'), h('y')]}))
expectType<Root>(h())
expectType<Root>(s())
// @ts-expect-error: not a tag name.
h(true)
expectType<Root>(h(null))
expectType<Root>(h(undefined))
expectType<Element>(h(''))
expectType<Element>(s(''))
expectType<Element>(h('', null))
expectType<Element>(h('', undefined))
expectType<Element>(h('', 1))
expectType<Element>(h('', 'a'))
// @ts-expect-error: not a child.
h('', true)
expectType<Element>(h('', [1, 'a', null]))
// @ts-expect-error: not a child.
h('', [true])
expectType<Element>(h('', {}))
expectType<Element>(h('', {}, [1, 'a', null]))
expectType<Element>(h('', {p: 1}))
expectType<Element>(h('', {p: null}))
expectType<Element>(h('', {p: undefined}))
expectType<Element>(h('', {p: true}))
expectType<Element>(h('', {p: false}))
expectType<Element>(h('', {p: 'a'}))
expectType<Element>(h('', {p: [1]}))
// @ts-expect-error: not a property value.
h('', {p: [true]})
expectType<Element>(h('', {p: ['a']}))
expectType<Element>(h('', {p: {x: 1}})) // Style
// @ts-expect-error: not a property value.
h('', {p: {x: true}})
declare const propsOrChild:
| Record<string, string | null | undefined>
| string
| null
| undefined
expectType<Element>(h('', propsOrChild))
expectType<Element>(
s('svg', {viewbox: '0 0 500 500', xmlns: 'http://www.w3.org/2000/svg'}, [
s('title', 'SVG `<circle` element'),
s('circle', {cx: 120, cy: 120, r: 100})
])
)