Skip to content

Commit f66c8e6

Browse files
authored
Fix missing renamed compiler flags (microsoft#40606)
1 parent a5babe1 commit f66c8e6

File tree

5 files changed

+39
-19
lines changed

5 files changed

+39
-19
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13922,7 +13922,7 @@ namespace ts {
1392213922
}
1392313923

1392413924
const shouldIncludeUndefined =
13925-
compilerOptions.noUncheckedIndexSignatures &&
13925+
compilerOptions.noUncheckedIndexedAccess &&
1392613926
(accessFlags & (AccessFlags.Writing | AccessFlags.ExpressionPosition)) === AccessFlags.ExpressionPosition;
1392713927

1392813928
// If the object type has a string index signature and no other members we know that the result will
@@ -20735,7 +20735,7 @@ namespace ts {
2073520735

2073620736
function includeUndefinedInIndexSignature(type: Type | undefined): Type | undefined {
2073720737
if (!type) return type;
20738-
return compilerOptions.noUncheckedIndexSignatures ?
20738+
return compilerOptions.noUncheckedIndexedAccess ?
2073920739
getUnionType([type, undefinedType]) :
2074020740
type;
2074120741
}
@@ -25478,7 +25478,7 @@ namespace ts {
2547825478
error(node, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(apparentType));
2547925479
}
2548025480

25481-
propType = (compilerOptions.noUncheckedIndexSignatures && !isAssignmentTarget(node)) ? getUnionType([indexInfo.type, undefinedType]) : indexInfo.type;
25481+
propType = (compilerOptions.noUncheckedIndexedAccess && !isAssignmentTarget(node)) ? getUnionType([indexInfo.type, undefinedType]) : indexInfo.type;
2548225482
}
2548325483
else {
2548425484
if (prop.valueDeclaration?.flags & NodeFlags.Deprecated && isUncalledFunctionReference(node, prop)) {
@@ -29445,7 +29445,7 @@ namespace ts {
2944529445
// present (aka the tuple element property). This call also checks that the parentType is in
2944629446
// fact an iterable or array (depending on target language).
2944729447
const possiblyOutOfBoundsType = checkIteratedTypeOrElementType(IterationUse.Destructuring | IterationUse.PossiblyOutOfBounds, sourceType, undefinedType, node) || errorType;
29448-
let inBoundsType: Type | undefined = compilerOptions.noUncheckedIndexSignatures ? undefined: possiblyOutOfBoundsType;
29448+
let inBoundsType: Type | undefined = compilerOptions.noUncheckedIndexedAccess ? undefined: possiblyOutOfBoundsType;
2944929449
for (let i = 0; i < elements.length; i++) {
2945029450
let type = possiblyOutOfBoundsType;
2945129451
if (node.elements[i].kind === SyntaxKind.SpreadElement) {
@@ -33709,7 +33709,7 @@ namespace ts {
3370933709

3371033710
const uplevelIteration = languageVersion >= ScriptTarget.ES2015;
3371133711
const downlevelIteration = !uplevelIteration && compilerOptions.downlevelIteration;
33712-
const possibleOutOfBounds = compilerOptions.noUncheckedIndexSignatures && !!(use & IterationUse.PossiblyOutOfBounds);
33712+
const possibleOutOfBounds = compilerOptions.noUncheckedIndexedAccess && !!(use & IterationUse.PossiblyOutOfBounds);
3371333713

3371433714
// Get the iterated type of an `Iterable<T>` or `IterableIterator<T>` only in ES2015
3371533715
// or higher, when inside of an async generator or for-await-if, or when
@@ -33804,7 +33804,7 @@ namespace ts {
3380433804
const arrayElementType = getIndexTypeOfType(arrayType, IndexKind.Number);
3380533805
if (hasStringConstituent && arrayElementType) {
3380633806
// This is just an optimization for the case where arrayOrStringType is string | string[]
33807-
if (arrayElementType.flags & TypeFlags.StringLike && !compilerOptions.noUncheckedIndexSignatures) {
33807+
if (arrayElementType.flags & TypeFlags.StringLike && !compilerOptions.noUncheckedIndexedAccess) {
3380833808
return stringType;
3380933809
}
3381033810

tests/baselines/reference/noUncheckedIndexedAccess.errors.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(3,32): error TS2344
22
Type 'undefined' is not assignable to type 'boolean'.
33
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(12,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
44
Type 'undefined' is not assignable to type 'boolean'.
5+
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(13,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
6+
Type 'undefined' is not assignable to type 'boolean'.
57
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(14,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
68
Type 'undefined' is not assignable to type 'boolean'.
79
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(15,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
@@ -49,7 +51,7 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(79,7): error TS2322
4951
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(85,1): error TS2322: Type 'undefined' is not assignable to type 'string'.
5052

5153

52-
==== tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts (27 errors) ====
54+
==== tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts (28 errors) ====
5355
type CheckBooleanOnly<T extends boolean> = any;
5456
// Validate CheckBooleanOnly works - should error
5557
type T_ERR1 = CheckBooleanOnly<boolean | undefined>;
@@ -69,6 +71,9 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(85,1): error TS2322
6971
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
7072
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
7173
const e2: boolean = strMap.bar;
74+
~~
75+
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
76+
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
7277
const e3: boolean = strMap[0];
7378
~~
7479
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.

tests/baselines/reference/noUncheckedIndexedAccess.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ const e1: boolean = strMap["foo"];
4141

4242
const e2: boolean = strMap.bar;
4343
>e2 : boolean
44-
>strMap.bar : boolean
44+
>strMap.bar : boolean | undefined
4545
>strMap : { [s: string]: boolean; }
46-
>bar : boolean
46+
>bar : boolean | undefined
4747

4848
const e3: boolean = strMap[0];
4949
>e3 : boolean
@@ -146,9 +146,9 @@ const ok1: boolean | undefined = strMap["foo"];
146146

147147
const ok2: boolean | undefined = strMap.bar;
148148
>ok2 : boolean | undefined
149-
>strMap.bar : boolean
149+
>strMap.bar : boolean | undefined
150150
>strMap : { [s: string]: boolean; }
151-
>bar : boolean
151+
>bar : boolean | undefined
152152

153153
type T_OK1 = CheckBooleanOnly<(typeof strMap)[string]>;
154154
>T_OK1 : any

tests/baselines/reference/noUncheckedIndexedAccessDestructuring.errors.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(8,1): error TS2532: Object is possibly 'undefined'.
12
tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(12,9): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'string'.
23
tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(16,9): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'string'.
4+
tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(23,1): error TS2532: Object is possibly 'undefined'.
5+
tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(26,1): error TS2532: Object is possibly 'undefined'.
6+
tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(34,5): error TS2532: Object is possibly 'undefined'.
7+
tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(41,5): error TS2532: Object is possibly 'undefined'.
38
tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(50,2): error TS2322: Type 'string | undefined' is not assignable to type 'string'.
49
Type 'undefined' is not assignable to type 'string'.
510
tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(59,8): error TS2322: Type 'number | undefined' is not assignable to type 'number'.
611
Type 'undefined' is not assignable to type 'number'.
712

813

9-
==== tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts (4 errors) ====
14+
==== tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts (9 errors) ====
1015
declare const strArray: string[];
1116
declare const strStrTuple: [string, string];
1217

@@ -15,6 +20,8 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(59,8):
1520
// Destructuring from a simple array -> include undefined
1621
const [s1] = strArray;
1722
s1.toString(); // Should error, s1 possibly undefined
23+
~~
24+
!!! error TS2532: Object is possibly 'undefined'.
1825

1926
// Destructuring a rest element -> do not include undefined
2027
const [...s2] = strArray;
@@ -34,9 +41,13 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(59,8):
3441

3542
const { t1 } = strMap;
3643
t1.toString(); // Should error, t1 possibly undefined
44+
~~
45+
!!! error TS2532: Object is possibly 'undefined'.
3746

3847
const { ...t2 } = strMap;
3948
t2.z.toString(); // Should error
49+
~~~~
50+
!!! error TS2532: Object is possibly 'undefined'.
4051

4152
// Test intersections with declared properties
4253
declare const numMapPoint: { x: number, y: number} & { [s: string]: number };
@@ -45,13 +56,17 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(59,8):
4556
x.toFixed(); // Should OK
4657
y.toFixed(); // Should OK
4758
z.toFixed(); // Should error
59+
~
60+
!!! error TS2532: Object is possibly 'undefined'.
4861
}
4962

5063
{
5164
const { x, ...q } = numMapPoint;
5265
x.toFixed(); // Should OK
5366
q.y.toFixed(); // Should OK
5467
q.z.toFixed(); // Should error
68+
~~~
69+
!!! error TS2532: Object is possibly 'undefined'.
5570
}
5671

5772

tests/baselines/reference/noUncheckedIndexedAccessDestructuring.types

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const [s1] = strArray;
1515
s1.toString(); // Should error, s1 possibly undefined
1616
>s1.toString() : string
1717
>s1.toString : () => string
18-
>s1 : string
18+
>s1 : string | undefined
1919
>toString : () => string
2020

2121
// Destructuring a rest element -> do not include undefined
@@ -57,7 +57,7 @@ const { t1 } = strMap;
5757
t1.toString(); // Should error, t1 possibly undefined
5858
>t1.toString() : string
5959
>t1.toString : () => string
60-
>t1 : string
60+
>t1 : string | undefined
6161
>toString : () => string
6262

6363
const { ...t2 } = strMap;
@@ -67,9 +67,9 @@ const { ...t2 } = strMap;
6767
t2.z.toString(); // Should error
6868
>t2.z.toString() : string
6969
>t2.z.toString : () => string
70-
>t2.z : string
70+
>t2.z : string | undefined
7171
>t2 : { [s: string]: string; }
72-
>z : string
72+
>z : string | undefined
7373
>toString : () => string
7474

7575
// Test intersections with declared properties
@@ -100,7 +100,7 @@ declare const numMapPoint: { x: number, y: number} & { [s: string]: number };
100100
z.toFixed(); // Should error
101101
>z.toFixed() : string
102102
>z.toFixed : (fractionDigits?: number | undefined) => string
103-
>z : number
103+
>z : number | undefined
104104
>toFixed : (fractionDigits?: number | undefined) => string
105105
}
106106

@@ -127,9 +127,9 @@ declare const numMapPoint: { x: number, y: number} & { [s: string]: number };
127127
q.z.toFixed(); // Should error
128128
>q.z.toFixed() : string
129129
>q.z.toFixed : (fractionDigits?: number | undefined) => string
130-
>q.z : number
130+
>q.z : number | undefined
131131
>q : { [s: string]: number; y: number; }
132-
>z : number
132+
>z : number | undefined
133133
>toFixed : (fractionDigits?: number | undefined) => string
134134
}
135135

0 commit comments

Comments
 (0)