@@ -12,11 +12,16 @@ describe('with object props', () => {
12
12
interface ExpectedProps {
13
13
a ?: number | undefined
14
14
b : string
15
+ e ?: Function
15
16
bb : string
16
17
cc ?: string [ ] | undefined
17
18
dd : string [ ]
19
+ ee ?: ( ) => string
20
+ ff ?: ( a : number , b : string ) => { a : boolean }
18
21
ccc ?: string [ ] | undefined
19
22
ddd : string [ ]
23
+ eee : ( ) => { a : string }
24
+ fff : ( a : number , b : string ) => { a : boolean }
20
25
}
21
26
22
27
type GT = string & { __brand : unknown }
@@ -29,6 +34,7 @@ describe('with object props', () => {
29
34
type : String ,
30
35
required : true
31
36
} ,
37
+ e : Function ,
32
38
// default value should infer type and make it non-void
33
39
bb : {
34
40
default : 'hello'
@@ -40,23 +46,42 @@ describe('with object props', () => {
40
46
type : Array as PropType < string [ ] > ,
41
47
required : true
42
48
} ,
49
+ // return type
50
+ ee : Function as PropType < ( ) => string > ,
51
+ // arguments + object return
52
+ ff : Function as PropType < ( a : number , b : string ) => { a : boolean } > ,
43
53
// explicit type casting with constructor
44
54
ccc : Array as ( ) => string [ ] ,
45
55
// required + contructor type casting
46
56
ddd : {
47
57
type : Array as ( ) => string [ ] ,
48
58
required : true
59
+ } ,
60
+ // required + object return
61
+ eee : {
62
+ type : Function as PropType < ( ) => { a : string } > ,
63
+ required : true
64
+ } ,
65
+ // required + arguments + object return
66
+ fff : {
67
+ type : Function as PropType < ( a : number , b : string ) => { a : boolean } > ,
68
+ required : true
49
69
}
50
70
} ,
51
71
setup ( props ) {
52
72
// type assertion. See https://github.com/SamVerschueren/tsd
53
73
expectType < ExpectedProps [ 'a' ] > ( props . a )
54
74
expectType < ExpectedProps [ 'b' ] > ( props . b )
75
+ expectType < ExpectedProps [ 'e' ] > ( props . e )
55
76
expectType < ExpectedProps [ 'bb' ] > ( props . bb )
56
77
expectType < ExpectedProps [ 'cc' ] > ( props . cc )
57
78
expectType < ExpectedProps [ 'dd' ] > ( props . dd )
79
+ expectType < ExpectedProps [ 'ee' ] > ( props . ee )
80
+ expectType < ExpectedProps [ 'ff' ] > ( props . ff )
58
81
expectType < ExpectedProps [ 'ccc' ] > ( props . ccc )
59
82
expectType < ExpectedProps [ 'ddd' ] > ( props . ddd )
83
+ expectType < ExpectedProps [ 'eee' ] > ( props . eee )
84
+ expectType < ExpectedProps [ 'fff' ] > ( props . fff )
60
85
61
86
// props should be readonly
62
87
expectError ( ( props . a = 1 ) )
@@ -76,23 +101,33 @@ describe('with object props', () => {
76
101
const props = this . $props
77
102
expectType < ExpectedProps [ 'a' ] > ( props . a )
78
103
expectType < ExpectedProps [ 'b' ] > ( props . b )
104
+ expectType < ExpectedProps [ 'e' ] > ( props . e )
79
105
expectType < ExpectedProps [ 'bb' ] > ( props . bb )
80
106
expectType < ExpectedProps [ 'cc' ] > ( props . cc )
81
107
expectType < ExpectedProps [ 'dd' ] > ( props . dd )
108
+ expectType < ExpectedProps [ 'ee' ] > ( props . ee )
109
+ expectType < ExpectedProps [ 'ff' ] > ( props . ff )
82
110
expectType < ExpectedProps [ 'ccc' ] > ( props . ccc )
83
111
expectType < ExpectedProps [ 'ddd' ] > ( props . ddd )
112
+ expectType < ExpectedProps [ 'eee' ] > ( props . eee )
113
+ expectType < ExpectedProps [ 'fff' ] > ( props . fff )
84
114
85
115
// props should be readonly
86
116
expectError ( ( props . a = 1 ) )
87
117
88
118
// should also expose declared props on `this`
89
119
expectType < ExpectedProps [ 'a' ] > ( this . a )
90
120
expectType < ExpectedProps [ 'b' ] > ( this . b )
121
+ expectType < ExpectedProps [ 'e' ] > ( this . e )
91
122
expectType < ExpectedProps [ 'bb' ] > ( this . bb )
92
123
expectType < ExpectedProps [ 'cc' ] > ( this . cc )
93
124
expectType < ExpectedProps [ 'dd' ] > ( this . dd )
125
+ expectType < ExpectedProps [ 'ee' ] > ( this . ee )
126
+ expectType < ExpectedProps [ 'ff' ] > ( this . ff )
94
127
expectType < ExpectedProps [ 'ccc' ] > ( this . ccc )
95
128
expectType < ExpectedProps [ 'ddd' ] > ( this . ddd )
129
+ expectType < ExpectedProps [ 'eee' ] > ( this . eee )
130
+ expectType < ExpectedProps [ 'fff' ] > ( this . fff )
96
131
97
132
// props on `this` should be readonly
98
133
expectError ( ( this . a = 1 ) )
@@ -115,10 +150,14 @@ describe('with object props', () => {
115
150
a = { 1 }
116
151
b = "b"
117
152
bb = "bb"
153
+ e = { ( ) => { } }
118
154
cc = { [ 'cc' ] }
119
155
dd = { [ 'dd' ] }
156
+ ee = { ( ) => 'ee' }
120
157
ccc = { [ 'ccc' ] }
121
158
ddd = { [ 'ddd' ] }
159
+ eee = { ( ) => ( { a : 'eee' } ) }
160
+ fff = { ( a , b ) => ( { a : a > + b } ) }
122
161
// should allow extraneous as attrs
123
162
class = "bar"
124
163
// should allow key
0 commit comments