-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathautomatic.tsx
More file actions
65 lines (54 loc) · 1.74 KB
/
Copy pathautomatic.tsx
File metadata and controls
65 lines (54 loc) · 1.74 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
62
63
64
65
/* @jsxRuntime automatic */
/* @jsxImportSource xastscript */
import {expectType} from 'tsd'
import type {Element, Root} from 'xast'
import {x} from '../index.js'
import {Fragment, jsx, jsxs} from '../jsx-runtime.js'
type Result = Element | Root
// JSX automatic runtime.
expectType<Root>(jsx(Fragment, {}))
expectType<Root>(jsx(Fragment, {children: x('x')}))
expectType<Element>(jsx('a', {}))
expectType<Element>(jsx('a', {children: 'a'}))
expectType<Element>(jsx('a', {children: x('x')}))
expectType<Element>(jsxs('a', {children: ['a', 'b']}))
expectType<Element>(jsxs('a', {children: [x('x'), x('y')]}))
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>{x()}</a>)
expectType<Result>(<a>{x('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 child.
expectType<Result>(<a invalid={{}} />)
// @ts-expect-error: not a valid child.
expectType<Result>(<a invalid={[1]} />)
// @ts-expect-error: not a valid child.
expectType<Result>(<a>{{invalid: 'child'}}</a>)
// 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 not supported.
expectType<Result>(<Bar />)