1
- import { expectError , expectAssignable } from 'tsd'
2
1
import {
3
2
describe ,
4
3
h ,
@@ -7,36 +6,48 @@ import {
7
6
Fragment ,
8
7
Teleport ,
9
8
Suspense ,
10
- Component
9
+ Component ,
10
+ expectError ,
11
+ expectAssignable
11
12
} from './index'
12
13
13
14
describe ( 'h inference w/ element' , ( ) => {
14
15
// key
15
16
h ( 'div' , { key : 1 } )
16
17
h ( 'div' , { key : 'foo' } )
18
+ // @ts -expect-error
17
19
expectError ( h ( 'div' , { key : [ ] } ) )
20
+ // @ts -expect-error
18
21
expectError ( h ( 'div' , { key : { } } ) )
19
22
// ref
20
23
h ( 'div' , { ref : 'foo' } )
21
24
h ( 'div' , { ref : ref ( null ) } )
22
25
h ( 'div' , { ref : el => { } } )
26
+ // @ts -expect-error
23
27
expectError ( h ( 'div' , { ref : [ ] } ) )
28
+ // @ts -expect-error
24
29
expectError ( h ( 'div' , { ref : { } } ) )
30
+ // @ts -expect-error
25
31
expectError ( h ( 'div' , { ref : 123 } ) )
26
32
} )
27
33
28
34
describe ( 'h inference w/ Fragment' , ( ) => {
29
35
// only accepts array children
30
36
h ( Fragment , [ 'hello' ] )
31
37
h ( Fragment , { key : 123 } , [ 'hello' ] )
38
+ // @ts -expect-error
32
39
expectError ( h ( Fragment , 'foo' ) )
40
+ // @ts -expect-error
33
41
expectError ( h ( Fragment , { key : 123 } , 'bar' ) )
34
42
} )
35
43
36
44
describe ( 'h inference w/ Teleport' , ( ) => {
37
45
h ( Teleport , { to : '#foo' } , 'hello' )
46
+ // @ts -expect-error
38
47
expectError ( h ( Teleport ) )
48
+ // @ts -expect-error
39
49
expectError ( h ( Teleport , { } ) )
50
+ // @ts -expect-error
40
51
expectError ( h ( Teleport , { to : '#foo' } ) )
41
52
} )
42
53
@@ -47,15 +58,19 @@ describe('h inference w/ Suspense', () => {
47
58
h ( Suspense , null , {
48
59
default : ( ) => 'foo'
49
60
} )
61
+ // @ts -expect-error
50
62
expectError ( h ( Suspense , { onResolve : 1 } ) )
51
63
} )
52
64
53
65
describe ( 'h inference w/ functional component' , ( ) => {
54
66
const Func = ( _props : { foo : string ; bar ?: number } ) => ''
55
67
h ( Func , { foo : 'hello' } )
56
68
h ( Func , { foo : 'hello' , bar : 123 } )
69
+ // @ts -expect-error
57
70
expectError ( h ( Func , { foo : 123 } ) )
71
+ // @ts -expect-error
58
72
expectError ( h ( Func , { } ) )
73
+ // @ts -expect-error
59
74
expectError ( h ( Func , { bar : 123 } ) )
60
75
} )
61
76
@@ -85,10 +100,11 @@ describe('h inference w/ defineComponent', () => {
85
100
h ( Foo , { bar : 1 , foo : 'ok' } )
86
101
// should allow extraneous props (attrs fallthrough)
87
102
h ( Foo , { bar : 1 , foo : 'ok' , class : 'extra' } )
88
- // should fail on missing required prop
103
+ // @ts -expect-error should fail on missing required prop
89
104
expectError ( h ( Foo , { } ) )
105
+ // @ts -expect-error
90
106
expectError ( h ( Foo , { foo : 'ok' } ) )
91
- // should fail on wrong type
107
+ // @ts -expect-error should fail on wrong type
92
108
expectError ( h ( Foo , { bar : 1 , foo : 1 } ) )
93
109
} )
94
110
@@ -101,10 +117,11 @@ describe('h inference w/ defineComponent + optional props', () => {
101
117
h ( Foo , { bar : 1 , foo : 'ok' } )
102
118
// should allow extraneous props (attrs fallthrough)
103
119
h ( Foo , { bar : 1 , foo : 'ok' , class : 'extra' } )
104
- // should fail on missing required prop
120
+ // @ts -expect-error should fail on missing required prop
105
121
expectError ( h ( Foo , { } ) )
122
+ // @ts -expect-error
106
123
expectError ( h ( Foo , { foo : 'ok' } ) )
107
- // should fail on wrong type
124
+ // @ts -expect-error should fail on wrong type
108
125
expectError ( h ( Foo , { bar : 1 , foo : 1 } ) )
109
126
} )
110
127
@@ -115,10 +132,11 @@ describe('h inference w/ defineComponent + direct function', () => {
115
132
h ( Foo , { bar : 1 , foo : 'ok' } )
116
133
// should allow extraneous props (attrs fallthrough)
117
134
h ( Foo , { bar : 1 , foo : 'ok' , class : 'extra' } )
118
- // should fail on missing required prop
135
+ // @ts -expect-error should fail on missing required prop
119
136
expectError ( h ( Foo , { } ) )
137
+ // @ts -expect-error
120
138
expectError ( h ( Foo , { foo : 'ok' } ) )
121
- // should fail on wrong type
139
+ // @ts -expect-error should fail on wrong type
122
140
expectError ( h ( Foo , { bar : 1 , foo : 1 } ) )
123
141
} )
124
142
0 commit comments