@@ -1044,7 +1044,7 @@ describe('inject', () => {
10441044 expectType < unknown > ( this . foo )
10451045 expectType < unknown > ( this . bar )
10461046 // @ts -expect-error
1047- expectError ( ( this . foobar = 1 ) )
1047+ this . foobar = 1
10481048 }
10491049 } )
10501050
@@ -1056,7 +1056,7 @@ describe('inject', () => {
10561056 expectType < unknown > ( this . foo )
10571057 expectType < unknown > ( this . bar )
10581058 // @ts -expect-error
1059- expectError ( ( this . foobar = 1 ) )
1059+ this . foobar = 1
10601060 }
10611061 } )
10621062
@@ -1076,7 +1076,7 @@ describe('inject', () => {
10761076 expectType < unknown > ( this . foo )
10771077 expectType < unknown > ( this . bar )
10781078 // @ts -expect-error
1079- expectError ( ( this . foobar = 1 ) )
1079+ this . foobar = 1
10801080 }
10811081 } )
10821082
@@ -1085,9 +1085,9 @@ describe('inject', () => {
10851085 props : [ 'a' , 'b' ] ,
10861086 created ( ) {
10871087 // @ts -expect-error
1088- expectError ( ( this . foo = 1 ) )
1088+ this . foo = 1
10891089 // @ts -expect-error
1090- expectError ( ( this . bar = 1 ) )
1090+ this . bar = 1
10911091 }
10921092 } )
10931093} )
@@ -1193,16 +1193,14 @@ describe('define attrs', () => {
11931193 test ( 'define attrs w/ object props' , ( ) => {
11941194 type CompAttrs = {
11951195 bar : number
1196- baz ?: string
11971196 }
11981197 const MyComp = defineComponent ( {
11991198 props : {
12001199 foo : String
12011200 } ,
12021201 attrs : Object as AttrsType < CompAttrs > ,
12031202 created ( ) {
1204- expectType < CompAttrs [ 'bar' ] > ( this . $attrs . bar )
1205- expectType < CompAttrs [ 'baz' ] > ( this . $attrs . baz )
1203+ expectType < number | undefined > ( this . $attrs . bar )
12061204 }
12071205 } )
12081206 expectType < JSX . Element > ( < MyComp foo = "1" bar = { 1 } /> )
@@ -1211,14 +1209,12 @@ describe('define attrs', () => {
12111209 test ( 'define attrs w/ array props' , ( ) => {
12121210 type CompAttrs = {
12131211 bar : number
1214- baz ?: string
12151212 }
12161213 const MyComp = defineComponent ( {
12171214 props : [ 'foo' ] ,
12181215 attrs : Object as AttrsType < CompAttrs > ,
12191216 created ( ) {
1220- expectType < CompAttrs [ 'bar' ] > ( this . $attrs . bar )
1221- expectType < CompAttrs [ 'baz' ] > ( this . $attrs . baz )
1217+ expectType < number | undefined > ( this . $attrs . bar )
12221218 }
12231219 } )
12241220 expectType < JSX . Element > ( < MyComp foo = "1" bar = { 1 } /> )
@@ -1227,13 +1223,11 @@ describe('define attrs', () => {
12271223 test ( 'define attrs w/ no props' , ( ) => {
12281224 type CompAttrs = {
12291225 bar : number
1230- baz ?: string
12311226 }
12321227 const MyComp = defineComponent ( {
12331228 attrs : Object as AttrsType < CompAttrs > ,
12341229 created ( ) {
1235- expectType < CompAttrs [ 'bar' ] > ( this . $attrs . bar )
1236- expectType < CompAttrs [ 'baz' ] > ( this . $attrs . baz )
1230+ expectType < number | undefined > ( this . $attrs . bar )
12371231 }
12381232 } )
12391233 expectType < JSX . Element > ( < MyComp bar = { 1 } /> )
@@ -1242,7 +1236,6 @@ describe('define attrs', () => {
12421236 test ( 'define attrs w/ composition api' , ( ) => {
12431237 type CompAttrs = {
12441238 bar : number
1245- baz ?: string
12461239 }
12471240 const MyComp = defineComponent ( {
12481241 props : {
@@ -1254,8 +1247,7 @@ describe('define attrs', () => {
12541247 attrs : Object as AttrsType < CompAttrs > ,
12551248 setup ( props , { attrs } ) {
12561249 expectType < string > ( props . foo )
1257- expectType < number > ( attrs . bar )
1258- expectType < string | undefined > ( attrs . baz )
1250+ expectType < number | undefined > ( attrs . bar )
12591251 }
12601252 } )
12611253 expectType < JSX . Element > ( < MyComp foo = "1" bar = { 1 } /> )
@@ -1264,13 +1256,10 @@ describe('define attrs', () => {
12641256 test ( 'define attrs w/ functional component' , ( ) => {
12651257 type CompAttrs = {
12661258 bar : number
1267- baz ?: string
12681259 }
12691260 const MyComp = defineComponent (
12701261 ( 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 )
12741263 return ( ) => (
12751264 // return a render function (both JSX and h() works)
12761265 < div > { props . foo } </ div >
@@ -1294,12 +1283,44 @@ describe('define attrs', () => {
12941283 attrs : Object as AttrsType < CompAttrs > ,
12951284 created ( ) {
12961285 // @ts -expect-error
1297- console . log ( this . $attrs . foo )
1286+ this . $attrs . foo
12981287 }
12991288 } )
13001289 expectType < JSX . Element > ( < MyComp foo = "1" /> )
13011290 } )
13021291
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+
13031324 test ( 'define attrs w/ no attrs' , ( ) => {
13041325 const MyComp = defineComponent ( {
13051326 props : {
0 commit comments