Skip to content

Commit 21d781f

Browse files
Fix incorrect name of index signature flag in implementation (microsoft#40541)
1 parent 8d6aecb commit 21d781f

8 files changed

+149
-34
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13643,7 +13643,7 @@ namespace ts {
1364313643
return undefined;
1364413644
}
1364513645
const shouldIncludeUndefined =
13646-
compilerOptions.noUncheckedIndexSignatures &&
13646+
compilerOptions.noUncheckedIndexedAccess &&
1364713647
(accessFlags & (AccessFlags.Writing | AccessFlags.ExpressionPosition)) === AccessFlags.ExpressionPosition;
1364813648
if (accessNode && !isTypeAssignableToKind(indexType, TypeFlags.String | TypeFlags.Number)) {
1364913649
const indexNode = getIndexNodeForAccessExpression(accessNode);

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5783,7 +5783,7 @@ namespace ts {
57835783
assumeChangesOnlyAffectDirectDependencies?: boolean;
57845784
noLib?: boolean;
57855785
noResolve?: boolean;
5786-
noUncheckedIndexSignatures?: boolean;
5786+
noUncheckedIndexedAccess?: boolean;
57875787
out?: string;
57885788
outDir?: string;
57895789
outFile?: string;

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2841,7 +2841,7 @@ declare namespace ts {
28412841
assumeChangesOnlyAffectDirectDependencies?: boolean;
28422842
noLib?: boolean;
28432843
noResolve?: boolean;
2844-
noUncheckedIndexSignatures?: boolean;
2844+
noUncheckedIndexedAccess?: boolean;
28452845
out?: string;
28462846
outDir?: string;
28472847
outFile?: string;

tests/baselines/reference/api/typescript.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2841,7 +2841,7 @@ declare namespace ts {
28412841
assumeChangesOnlyAffectDirectDependencies?: boolean;
28422842
noLib?: boolean;
28432843
noResolve?: boolean;
2844-
noUncheckedIndexSignatures?: boolean;
2844+
noUncheckedIndexedAccess?: boolean;
28452845
out?: string;
28462846
outDir?: string;
28472847
outFile?: string;

tests/baselines/reference/noUncheckedIndexedAccess.errors.txt

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,55 @@
11
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(3,32): error TS2344: Type 'boolean | undefined' does not satisfy the constraint 'boolean'.
22
Type 'undefined' is not assignable to type 'boolean'.
3+
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(12,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
4+
Type 'undefined' is not assignable to type 'boolean'.
5+
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(14,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
6+
Type 'undefined' is not assignable to type 'boolean'.
7+
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(15,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
8+
Type 'undefined' is not assignable to type 'boolean'.
9+
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(16,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
10+
Type 'undefined' is not assignable to type 'boolean'.
11+
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(17,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
12+
Type 'undefined' is not assignable to type 'boolean'.
13+
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(18,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
14+
Type 'undefined' is not assignable to type 'boolean'.
15+
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(19,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
16+
Type 'undefined' is not assignable to type 'boolean'.
17+
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(20,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
18+
Type 'undefined' is not assignable to type 'boolean'.
19+
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(21,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
20+
Type 'undefined' is not assignable to type 'boolean'.
21+
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(22,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
22+
Type 'undefined' is not assignable to type 'boolean'.
23+
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(23,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
24+
Type 'undefined' is not assignable to type 'boolean'.
25+
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(24,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
26+
Type 'undefined' is not assignable to type 'boolean'.
27+
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(25,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
28+
Type 'undefined' is not assignable to type 'boolean'.
329
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(38,1): error TS2322: Type 'undefined' is not assignable to type 'boolean'.
430
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(39,1): error TS2322: Type 'undefined' is not assignable to type 'boolean'.
531
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(40,1): error TS2322: Type 'undefined' is not assignable to type 'boolean'.
632
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(41,1): error TS2322: Type 'undefined' is not assignable to type 'boolean'.
33+
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(46,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
34+
Type 'undefined' is not assignable to type 'boolean'.
35+
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(47,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
36+
Type 'undefined' is not assignable to type 'boolean'.
37+
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(48,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
38+
Type 'undefined' is not assignable to type 'boolean'.
39+
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(49,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
40+
Type 'undefined' is not assignable to type 'boolean'.
41+
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(50,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
42+
Type 'undefined' is not assignable to type 'boolean'.
43+
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(55,5): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
44+
Type 'undefined' is not assignable to type 'boolean'.
45+
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(63,5): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
46+
Type 'undefined' is not assignable to type 'boolean'.
47+
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(79,7): error TS2322: Type 'number | boolean | undefined' is not assignable to type 'number | boolean'.
48+
Type 'undefined' is not assignable to type 'number | boolean'.
749
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(85,1): error TS2322: Type 'undefined' is not assignable to type 'string'.
850

951

10-
==== tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts (6 errors) ====
52+
==== tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts (27 errors) ====
1153
type CheckBooleanOnly<T extends boolean> = any;
1254
// Validate CheckBooleanOnly works - should error
1355
type T_ERR1 = CheckBooleanOnly<boolean | undefined>;
@@ -23,19 +65,58 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(85,1): error TS2322
2365

2466
// All of these should be errors
2567
const e1: boolean = strMap["foo"];
68+
~~
69+
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
70+
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
2671
const e2: boolean = strMap.bar;
2772
const e3: boolean = strMap[0];
73+
~~
74+
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
75+
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
2876
const e4: boolean = strMap[0 as string | number];
77+
~~
78+
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
79+
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
2980
const e5: boolean = strMap[0 as string | 0 | 1];
81+
~~
82+
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
83+
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
3084
const e6: boolean = strMap[0 as 0 | 1];
85+
~~
86+
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
87+
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
3188
const e7: boolean = strMap["foo" as "foo" | "baz"];
89+
~~
90+
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
91+
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
3292
const e8: boolean = strMap[NumericEnum1.A];
93+
~~
94+
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
95+
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
3396
const e9: boolean = strMap[NumericEnum2.A];
97+
~~
98+
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
99+
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
34100
const e10: boolean = strMap[StringEnum1.A];
101+
~~~
102+
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
103+
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
35104
const e11: boolean = strMap[StringEnum1.A as StringEnum1];
105+
~~~
106+
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
107+
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
36108
const e12: boolean = strMap[NumericEnum1.A as NumericEnum1];
109+
~~~
110+
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
111+
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
37112
const e13: boolean = strMap[NumericEnum2.A as NumericEnum2];
113+
~~~
114+
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
115+
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
38116
const e14: boolean = strMap[null as any];
117+
~~~
118+
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
119+
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
39120

40121
// Should be OK
41122
const ok1: boolean | undefined = strMap["foo"];
@@ -65,15 +146,33 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(85,1): error TS2322
65146
declare const numMap: { [s: number]: boolean };
66147
// All of these should be ok
67148
const num_ok1: boolean = numMap[0];
149+
~~~~~~~
150+
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
151+
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
68152
const num_ok2: boolean = numMap[0 as number];
153+
~~~~~~~
154+
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
155+
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
69156
const num_ok3: boolean = numMap[0 as 0 | 1];
157+
~~~~~~~
158+
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
159+
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
70160
const num_ok4: boolean = numMap[NumericEnum1.A];
161+
~~~~~~~
162+
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
163+
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
71164
const num_ok5: boolean = numMap[NumericEnum2.A];
165+
~~~~~~~
166+
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
167+
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
72168

73169
// Generics
74170
function generic1<T extends { [s: string]: boolean }>(arg: T): boolean {
75171
// Should error
76172
return arg["blah"];
173+
~~~~~~~~~~~~~~~~~~~
174+
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
175+
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
77176
}
78177
function generic2<T extends { [s: string]: boolean }>(arg: T): boolean {
79178
// Should OK
@@ -82,6 +181,9 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(85,1): error TS2322
82181
function generic3<T extends string>(arg: T): boolean {
83182
// Should error
84183
return strMap[arg];
184+
~~~~~~~~~~~~~~~~~~~
185+
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
186+
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
85187
}
86188

87189
// Element access into known properties is ok
@@ -98,6 +200,9 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(85,1): error TS2322
98200
declare const strMapUnion: { [s: string]: boolean } | { [s: string]: number };
99201
// Should error
100202
const f1: boolean | number = strMapUnion["foo"];
203+
~~
204+
!!! error TS2322: Type 'number | boolean | undefined' is not assignable to type 'number | boolean'.
205+
!!! error TS2322: Type 'undefined' is not assignable to type 'number | boolean'.
101206

102207
// Symbol index signatures
103208
declare const s: unique symbol;

0 commit comments

Comments
 (0)