diff --git a/tests/no_unchecked_indexed_access/arr_test.js b/tests/no_unchecked_indexed_access/arr_test.js index 2f60cffecfb..d9ab9876c43 100644 --- a/tests/no_unchecked_indexed_access/arr_test.js +++ b/tests/no_unchecked_indexed_access/arr_test.js @@ -12,3 +12,6 @@ tuple[1] as 1; tuple[2] as 2; tuple[3] as number; // error: out of bound tuple[key] as number; // error: void ~> number + +declare const typeTest: (typeof roArray)[number]; +typeTest as string; // todo: the flag should not affect type-level acccess diff --git a/tests/no_unchecked_indexed_access/no_unchecked_indexed_access.exp b/tests/no_unchecked_indexed_access/no_unchecked_indexed_access.exp index 60d90925849..0a4c5c35a7b 100644 --- a/tests/no_unchecked_indexed_access/no_unchecked_indexed_access.exp +++ b/tests/no_unchecked_indexed_access/no_unchecked_indexed_access.exp @@ -97,6 +97,23 @@ References: ^^^^^^ [2] +Error ------------------------------------------------------------------------------------------------- arr_test.js:17:1 + +Cannot cast `typeTest` to string because undefined [1] is incompatible with string [2]. [incompatible-cast] + + arr_test.js:17:1 + 17| typeTest as string; // todo: the flag should not affect type-level acccess + ^^^^^^^^ + +References: + arr_test.js:3:39 + 3| declare const roArray: $ReadOnlyArray; + ^^^^^^ [1] + arr_test.js:17:13 + 17| typeTest as string; // todo: the flag should not affect type-level acccess + ^^^^^^ [2] + + Error ------------------------------------------------------------------------------------------------- obj_test.js:5:11 Cannot access object with computed property using string [1]. [invalid-computed-prop] @@ -145,5 +162,22 @@ References: ^^^^^^ [2] +Error ------------------------------------------------------------------------------------------------- obj_test.js:10:1 + +Cannot cast `typeTest` to string because undefined [1] is incompatible with string [2]. [incompatible-cast] + + obj_test.js:10:1 + 10| typeTest as string; // todo: the flag should not affect type-level acccess + ^^^^^^^^ + +References: + obj_test.js:2:35 + 2| declare const dictObj: {[string]: string}; + ^^^^^^ [1] + obj_test.js:10:13 + 10| typeTest as string; // todo: the flag should not affect type-level acccess + ^^^^^^ [2] + + -Found 9 errors +Found 11 errors diff --git a/tests/no_unchecked_indexed_access/obj_test.js b/tests/no_unchecked_indexed_access/obj_test.js index 0e1baf15de8..f2bc5a04071 100644 --- a/tests/no_unchecked_indexed_access/obj_test.js +++ b/tests/no_unchecked_indexed_access/obj_test.js @@ -5,3 +5,6 @@ declare const key: string; recordObj[key] as string; // error: bad key dictObj[key] as string; // error: void ~> string dictObj.hahaha as string; // error: void ~> string + +declare const typeTest: (typeof dictObj)[string]; +typeTest as string; // todo: the flag should not affect type-level acccess