@@ -1044,7 +1044,7 @@ describe('inject', () => {
1044
1044
expectType < unknown > ( this . foo )
1045
1045
expectType < unknown > ( this . bar )
1046
1046
// @ts -expect-error
1047
- expectError ( ( this . foobar = 1 ) )
1047
+ this . foobar = 1
1048
1048
}
1049
1049
} )
1050
1050
@@ -1056,7 +1056,7 @@ describe('inject', () => {
1056
1056
expectType < unknown > ( this . foo )
1057
1057
expectType < unknown > ( this . bar )
1058
1058
// @ts -expect-error
1059
- expectError ( ( this . foobar = 1 ) )
1059
+ this . foobar = 1
1060
1060
}
1061
1061
} )
1062
1062
@@ -1076,7 +1076,7 @@ describe('inject', () => {
1076
1076
expectType < unknown > ( this . foo )
1077
1077
expectType < unknown > ( this . bar )
1078
1078
// @ts -expect-error
1079
- expectError ( ( this . foobar = 1 ) )
1079
+ this . foobar = 1
1080
1080
}
1081
1081
} )
1082
1082
@@ -1085,9 +1085,9 @@ describe('inject', () => {
1085
1085
props : [ 'a' , 'b' ] ,
1086
1086
created ( ) {
1087
1087
// @ts -expect-error
1088
- expectError ( ( this . foo = 1 ) )
1088
+ this . foo = 1
1089
1089
// @ts -expect-error
1090
- expectError ( ( this . bar = 1 ) )
1090
+ this . bar = 1
1091
1091
}
1092
1092
} )
1093
1093
} )
@@ -1193,16 +1193,14 @@ describe('define attrs', () => {
1193
1193
test ( 'define attrs w/ object props' , ( ) => {
1194
1194
type CompAttrs = {
1195
1195
bar : number
1196
- baz ?: string
1197
1196
}
1198
1197
const MyComp = defineComponent ( {
1199
1198
props : {
1200
1199
foo : String
1201
1200
} ,
1202
1201
attrs : Object as AttrsType < CompAttrs > ,
1203
1202
created ( ) {
1204
- expectType < CompAttrs [ 'bar' ] > ( this . $attrs . bar )
1205
- expectType < CompAttrs [ 'baz' ] > ( this . $attrs . baz )
1203
+ expectType < number | undefined > ( this . $attrs . bar )
1206
1204
}
1207
1205
} )
1208
1206
expectType < JSX . Element > ( < MyComp foo = "1" bar = { 1 } /> )
@@ -1211,14 +1209,12 @@ describe('define attrs', () => {
1211
1209
test ( 'define attrs w/ array props' , ( ) => {
1212
1210
type CompAttrs = {
1213
1211
bar : number
1214
- baz ?: string
1215
1212
}
1216
1213
const MyComp = defineComponent ( {
1217
1214
props : [ 'foo' ] ,
1218
1215
attrs : Object as AttrsType < CompAttrs > ,
1219
1216
created ( ) {
1220
- expectType < CompAttrs [ 'bar' ] > ( this . $attrs . bar )
1221
- expectType < CompAttrs [ 'baz' ] > ( this . $attrs . baz )
1217
+ expectType < number | undefined > ( this . $attrs . bar )
1222
1218
}
1223
1219
} )
1224
1220
expectType < JSX . Element > ( < MyComp foo = "1" bar = { 1 } /> )
@@ -1227,13 +1223,11 @@ describe('define attrs', () => {
1227
1223
test ( 'define attrs w/ no props' , ( ) => {
1228
1224
type CompAttrs = {
1229
1225
bar : number
1230
- baz ?: string
1231
1226
}
1232
1227
const MyComp = defineComponent ( {
1233
1228
attrs : Object as AttrsType < CompAttrs > ,
1234
1229
created ( ) {
1235
- expectType < CompAttrs [ 'bar' ] > ( this . $attrs . bar )
1236
- expectType < CompAttrs [ 'baz' ] > ( this . $attrs . baz )
1230
+ expectType < number | undefined > ( this . $attrs . bar )
1237
1231
}
1238
1232
} )
1239
1233
expectType < JSX . Element > ( < MyComp bar = { 1 } /> )
@@ -1242,7 +1236,6 @@ describe('define attrs', () => {
1242
1236
test ( 'define attrs w/ composition api' , ( ) => {
1243
1237
type CompAttrs = {
1244
1238
bar : number
1245
- baz ?: string
1246
1239
}
1247
1240
const MyComp = defineComponent ( {
1248
1241
props : {
@@ -1254,8 +1247,7 @@ describe('define attrs', () => {
1254
1247
attrs : Object as AttrsType < CompAttrs > ,
1255
1248
setup ( props , { attrs } ) {
1256
1249
expectType < string > ( props . foo )
1257
- expectType < number > ( attrs . bar )
1258
- expectType < string | undefined > ( attrs . baz )
1250
+ expectType < number | undefined > ( attrs . bar )
1259
1251
}
1260
1252
} )
1261
1253
expectType < JSX . Element > ( < MyComp foo = "1" bar = { 1 } /> )
@@ -1264,13 +1256,10 @@ describe('define attrs', () => {
1264
1256
test ( 'define attrs w/ functional component' , ( ) => {
1265
1257
type CompAttrs = {
1266
1258
bar : number
1267
- baz ?: string
1268
1259
}
1269
1260
const MyComp = defineComponent (
1270
1261
( props : { foo : string } , ctx ) => {
1271
- expectType < number > ( ctx . attrs . bar )
1272
- expectType < CompAttrs [ 'bar' ] > ( ctx . attrs . bar )
1273
- expectType < CompAttrs [ 'baz' ] > ( ctx . attrs . baz )
1262
+ expectType < number | undefined > ( ctx . attrs . bar )
1274
1263
return ( ) => (
1275
1264
// return a render function (both JSX and h() works)
1276
1265
< div > { props . foo } </ div >
@@ -1294,12 +1283,44 @@ describe('define attrs', () => {
1294
1283
attrs : Object as AttrsType < CompAttrs > ,
1295
1284
created ( ) {
1296
1285
// @ts -expect-error
1297
- console . log ( this . $attrs . foo )
1286
+ this . $attrs . foo
1298
1287
}
1299
1288
} )
1300
1289
expectType < JSX . Element > ( < MyComp foo = "1" /> )
1301
1290
} )
1302
1291
1292
+ test ( 'attrs is always optional w/ object props' , ( ) => {
1293
+ type CompAttrs = {
1294
+ bar : number
1295
+ }
1296
+ const MyComp = defineComponent ( {
1297
+ attrs : Object as AttrsType < CompAttrs > ,
1298
+ created ( ) {
1299
+ expectType < number | undefined > ( this . $attrs . bar )
1300
+ }
1301
+ } )
1302
+ expectType < JSX . Element > ( < MyComp /> )
1303
+ } )
1304
+
1305
+ test ( 'attrs is always optional w/ functional component' , ( ) => {
1306
+ type CompAttrs = {
1307
+ bar : number
1308
+ }
1309
+ const MyComp = defineComponent (
1310
+ ( props : { foo : string } , ctx ) => {
1311
+ expectType < number | undefined > ( ctx . attrs . bar )
1312
+ return ( ) => (
1313
+ // return a render function (both JSX and h() works)
1314
+ < div > { props . foo } </ div >
1315
+ )
1316
+ } ,
1317
+ {
1318
+ attrs : Object as AttrsType < CompAttrs >
1319
+ }
1320
+ )
1321
+ expectType < JSX . Element > ( < MyComp foo = { '1' } /> )
1322
+ } )
1323
+
1303
1324
test ( 'define attrs w/ no attrs' , ( ) => {
1304
1325
const MyComp = defineComponent ( {
1305
1326
props : {
0 commit comments