-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
automatic-h.tsx
50 lines (42 loc) · 1.19 KB
/
automatic-h.tsx
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
/* @jsxRuntime automatic */
/* @jsxImportSource hastscript */
import {expectType} from 'tsd'
import type {Root, Element} from 'hast'
import {h} from '../index.js'
type Result = Element | Root
// JSX automatic runtime.
expectType<Result>(<></>)
expectType<Result>(<a />)
expectType<Result>(<a b="c" />)
expectType<Result>(<a b={'c'} />)
expectType<Result>(<a>string</a>)
expectType<Result>(<a>{['string', 'string']}</a>)
expectType<Result>(
<a>
<></>
</a>
)
expectType<Result>(<a>{h()}</a>)
expectType<Result>(<a>{h('b')}</a>)
expectType<Result>(
<a>
<b />c
</a>
)
expectType<Result>(
<a>
<b />
<c />
</a>
)
expectType<Result>(<a>{[<b />, <c />]}</a>)
expectType<Result>(<a>{[<b />, <c />]}</a>)
expectType<Result>(<a>{[]}</a>)
// @ts-expect-error: not a valid property value.
const a = <a invalid={[true]} />
// This is where the automatic runtime differs from the classic runtime.
// The automatic runtime the children prop to define JSX children, whereas it’s used as an attribute in the classic runtime.
expectType<Result>(<a children={<b />} />)
declare function Bar(props?: Record<string, unknown>): Element
// @ts-expect-error: components are not supported.
const b = <Bar />