@@ -27,6 +27,7 @@ describe('with object props', () => {
27
27
eee : ( ) => { a : string }
28
28
fff : ( a : number , b : string ) => { a : boolean }
29
29
hhh : boolean
30
+ ggg : 'foo' | 'bar'
30
31
validated ?: string
31
32
}
32
33
@@ -77,6 +78,11 @@ describe('with object props', () => {
77
78
type : Boolean ,
78
79
required : true
79
80
} ,
81
+ // default + type casting
82
+ ggg : {
83
+ type : String as PropType < 'foo' | 'bar' > ,
84
+ default : 'foo'
85
+ } ,
80
86
validated : {
81
87
type : String ,
82
88
validator : ( val : unknown ) => val !== ''
@@ -97,6 +103,7 @@ describe('with object props', () => {
97
103
expectType < ExpectedProps [ 'eee' ] > ( props . eee )
98
104
expectType < ExpectedProps [ 'fff' ] > ( props . fff )
99
105
expectType < ExpectedProps [ 'hhh' ] > ( props . hhh )
106
+ expectType < ExpectedProps [ 'ggg' ] > ( props . ggg )
100
107
expectType < ExpectedProps [ 'validated' ] > ( props . validated )
101
108
102
109
// @ts -expect-error props should be readonly
@@ -128,6 +135,7 @@ describe('with object props', () => {
128
135
expectType < ExpectedProps [ 'eee' ] > ( props . eee )
129
136
expectType < ExpectedProps [ 'fff' ] > ( props . fff )
130
137
expectType < ExpectedProps [ 'hhh' ] > ( props . hhh )
138
+ expectType < ExpectedProps [ 'ggg' ] > ( props . ggg )
131
139
132
140
// @ts -expect-error props should be readonly
133
141
expectError ( ( props . a = 1 ) )
@@ -146,6 +154,7 @@ describe('with object props', () => {
146
154
expectType < ExpectedProps [ 'eee' ] > ( this . eee )
147
155
expectType < ExpectedProps [ 'fff' ] > ( this . fff )
148
156
expectType < ExpectedProps [ 'hhh' ] > ( this . hhh )
157
+ expectType < ExpectedProps [ 'ggg' ] > ( this . ggg )
149
158
150
159
// @ts -expect-error props on `this` should be readonly
151
160
expectError ( ( this . a = 1 ) )
@@ -177,6 +186,7 @@ describe('with object props', () => {
177
186
eee = { ( ) => ( { a : 'eee' } ) }
178
187
fff = { ( a , b ) => ( { a : a > + b } ) }
179
188
hhh = { false }
189
+ ggg = "foo"
180
190
// should allow class/style as attrs
181
191
class = "bar"
182
192
style = { { color : 'red' } }
@@ -194,6 +204,10 @@ describe('with object props', () => {
194
204
// @ts -expect-error wrong prop types
195
205
< MyComponent a = { 'wrong type' } b = "foo" dd = { { n : 1 } } ddd = { [ 'foo' ] } />
196
206
)
207
+ expectError (
208
+ // @ts -expect-error wrong prop types
209
+ < MyComponent ggg = "baz" />
210
+ )
197
211
// @ts -expect-error
198
212
expectError ( < MyComponent b = "foo" dd = { { n : 'string' } } ddd = { [ 'foo' ] } /> )
199
213
} )
0 commit comments