From 21d781fa548bb4e16f613822f85e50fb2ad27b1f Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 14 Sep 2020 09:32:22 -0700 Subject: [PATCH] Fix incorrect name of index signature flag in implementation (#40541) --- src/compiler/checker.ts | 2 +- src/compiler/types.ts | 2 +- .../reference/api/tsserverlibrary.d.ts | 2 +- tests/baselines/reference/api/typescript.d.ts | 2 +- .../noUncheckedIndexedAccess.errors.txt | 107 +++++++++++++++++- .../reference/noUncheckedIndexedAccess.types | 50 ++++---- ...eckedIndexedAccessDestructuring.errors.txt | 12 +- ...oUncheckedIndexedAccessDestructuring.types | 6 +- 8 files changed, 149 insertions(+), 34 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d9afe5e47ec..b80e64def78 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13643,7 +13643,7 @@ namespace ts { return undefined; } const shouldIncludeUndefined = - compilerOptions.noUncheckedIndexSignatures && + compilerOptions.noUncheckedIndexedAccess && (accessFlags & (AccessFlags.Writing | AccessFlags.ExpressionPosition)) === AccessFlags.ExpressionPosition; if (accessNode && !isTypeAssignableToKind(indexType, TypeFlags.String | TypeFlags.Number)) { const indexNode = getIndexNodeForAccessExpression(accessNode); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 71d64d3c65b..c804e49647c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -5783,7 +5783,7 @@ namespace ts { assumeChangesOnlyAffectDirectDependencies?: boolean; noLib?: boolean; noResolve?: boolean; - noUncheckedIndexSignatures?: boolean; + noUncheckedIndexedAccess?: boolean; out?: string; outDir?: string; outFile?: string; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 2e5b82492ba..58167e3f7b9 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2841,7 +2841,7 @@ declare namespace ts { assumeChangesOnlyAffectDirectDependencies?: boolean; noLib?: boolean; noResolve?: boolean; - noUncheckedIndexSignatures?: boolean; + noUncheckedIndexedAccess?: boolean; out?: string; outDir?: string; outFile?: string; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 5810c60b467..3a4fc7ae36e 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2841,7 +2841,7 @@ declare namespace ts { assumeChangesOnlyAffectDirectDependencies?: boolean; noLib?: boolean; noResolve?: boolean; - noUncheckedIndexSignatures?: boolean; + noUncheckedIndexedAccess?: boolean; out?: string; outDir?: string; outFile?: string; diff --git a/tests/baselines/reference/noUncheckedIndexedAccess.errors.txt b/tests/baselines/reference/noUncheckedIndexedAccess.errors.txt index 9177245e367..065eafcc65c 100644 --- a/tests/baselines/reference/noUncheckedIndexedAccess.errors.txt +++ b/tests/baselines/reference/noUncheckedIndexedAccess.errors.txt @@ -1,13 +1,55 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(3,32): error TS2344: Type 'boolean | undefined' does not satisfy the constraint 'boolean'. Type 'undefined' is not assignable to type 'boolean'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(12,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. + Type 'undefined' is not assignable to type 'boolean'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(14,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. + Type 'undefined' is not assignable to type 'boolean'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(15,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. + Type 'undefined' is not assignable to type 'boolean'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(16,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. + Type 'undefined' is not assignable to type 'boolean'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(17,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. + Type 'undefined' is not assignable to type 'boolean'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(18,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. + Type 'undefined' is not assignable to type 'boolean'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(19,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. + Type 'undefined' is not assignable to type 'boolean'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(20,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. + Type 'undefined' is not assignable to type 'boolean'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(21,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. + Type 'undefined' is not assignable to type 'boolean'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(22,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. + Type 'undefined' is not assignable to type 'boolean'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(23,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. + Type 'undefined' is not assignable to type 'boolean'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(24,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. + Type 'undefined' is not assignable to type 'boolean'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(25,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. + Type 'undefined' is not assignable to type 'boolean'. tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(38,1): error TS2322: Type 'undefined' is not assignable to type 'boolean'. tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(39,1): error TS2322: Type 'undefined' is not assignable to type 'boolean'. tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(40,1): error TS2322: Type 'undefined' is not assignable to type 'boolean'. tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(41,1): error TS2322: Type 'undefined' is not assignable to type 'boolean'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(46,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. + Type 'undefined' is not assignable to type 'boolean'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(47,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. + Type 'undefined' is not assignable to type 'boolean'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(48,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. + Type 'undefined' is not assignable to type 'boolean'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(49,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. + Type 'undefined' is not assignable to type 'boolean'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(50,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. + Type 'undefined' is not assignable to type 'boolean'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(55,5): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. + Type 'undefined' is not assignable to type 'boolean'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(63,5): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. + Type 'undefined' is not assignable to type 'boolean'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(79,7): error TS2322: Type 'number | boolean | undefined' is not assignable to type 'number | boolean'. + Type 'undefined' is not assignable to type 'number | boolean'. tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(85,1): error TS2322: Type 'undefined' is not assignable to type 'string'. -==== tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts (6 errors) ==== +==== tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts (27 errors) ==== type CheckBooleanOnly = any; // Validate CheckBooleanOnly works - should error type T_ERR1 = CheckBooleanOnly; @@ -23,19 +65,58 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(85,1): error TS2322 // All of these should be errors const e1: boolean = strMap["foo"]; + ~~ +!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. +!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'. const e2: boolean = strMap.bar; const e3: boolean = strMap[0]; + ~~ +!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. +!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'. const e4: boolean = strMap[0 as string | number]; + ~~ +!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. +!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'. const e5: boolean = strMap[0 as string | 0 | 1]; + ~~ +!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. +!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'. const e6: boolean = strMap[0 as 0 | 1]; + ~~ +!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. +!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'. const e7: boolean = strMap["foo" as "foo" | "baz"]; + ~~ +!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. +!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'. const e8: boolean = strMap[NumericEnum1.A]; + ~~ +!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. +!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'. const e9: boolean = strMap[NumericEnum2.A]; + ~~ +!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. +!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'. const e10: boolean = strMap[StringEnum1.A]; + ~~~ +!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. +!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'. const e11: boolean = strMap[StringEnum1.A as StringEnum1]; + ~~~ +!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. +!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'. const e12: boolean = strMap[NumericEnum1.A as NumericEnum1]; + ~~~ +!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. +!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'. const e13: boolean = strMap[NumericEnum2.A as NumericEnum2]; + ~~~ +!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. +!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'. const e14: boolean = strMap[null as any]; + ~~~ +!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. +!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'. // Should be OK const ok1: boolean | undefined = strMap["foo"]; @@ -65,15 +146,33 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(85,1): error TS2322 declare const numMap: { [s: number]: boolean }; // All of these should be ok const num_ok1: boolean = numMap[0]; + ~~~~~~~ +!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. +!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'. const num_ok2: boolean = numMap[0 as number]; + ~~~~~~~ +!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. +!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'. const num_ok3: boolean = numMap[0 as 0 | 1]; + ~~~~~~~ +!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. +!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'. const num_ok4: boolean = numMap[NumericEnum1.A]; + ~~~~~~~ +!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. +!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'. const num_ok5: boolean = numMap[NumericEnum2.A]; + ~~~~~~~ +!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. +!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'. // Generics function generic1(arg: T): boolean { // Should error return arg["blah"]; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. +!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'. } function generic2(arg: T): boolean { // Should OK @@ -82,6 +181,9 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(85,1): error TS2322 function generic3(arg: T): boolean { // Should error return strMap[arg]; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'. +!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'. } // Element access into known properties is ok @@ -98,6 +200,9 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(85,1): error TS2322 declare const strMapUnion: { [s: string]: boolean } | { [s: string]: number }; // Should error const f1: boolean | number = strMapUnion["foo"]; + ~~ +!!! error TS2322: Type 'number | boolean | undefined' is not assignable to type 'number | boolean'. +!!! error TS2322: Type 'undefined' is not assignable to type 'number | boolean'. // Symbol index signatures declare const s: unique symbol; diff --git a/tests/baselines/reference/noUncheckedIndexedAccess.types b/tests/baselines/reference/noUncheckedIndexedAccess.types index 1aa356cf5d1..7d1e910a95d 100644 --- a/tests/baselines/reference/noUncheckedIndexedAccess.types +++ b/tests/baselines/reference/noUncheckedIndexedAccess.types @@ -35,7 +35,7 @@ declare const strMap: { [s: string]: boolean }; // All of these should be errors const e1: boolean = strMap["foo"]; >e1 : boolean ->strMap["foo"] : boolean +>strMap["foo"] : boolean | undefined >strMap : { [s: string]: boolean; } >"foo" : "foo" @@ -47,41 +47,41 @@ const e2: boolean = strMap.bar; const e3: boolean = strMap[0]; >e3 : boolean ->strMap[0] : boolean +>strMap[0] : boolean | undefined >strMap : { [s: string]: boolean; } >0 : 0 const e4: boolean = strMap[0 as string | number]; >e4 : boolean ->strMap[0 as string | number] : boolean +>strMap[0 as string | number] : boolean | undefined >strMap : { [s: string]: boolean; } >0 as string | number : string | number >0 : 0 const e5: boolean = strMap[0 as string | 0 | 1]; >e5 : boolean ->strMap[0 as string | 0 | 1] : boolean +>strMap[0 as string | 0 | 1] : boolean | undefined >strMap : { [s: string]: boolean; } >0 as string | 0 | 1 : string | 0 | 1 >0 : 0 const e6: boolean = strMap[0 as 0 | 1]; >e6 : boolean ->strMap[0 as 0 | 1] : boolean +>strMap[0 as 0 | 1] : boolean | undefined >strMap : { [s: string]: boolean; } >0 as 0 | 1 : 0 | 1 >0 : 0 const e7: boolean = strMap["foo" as "foo" | "baz"]; >e7 : boolean ->strMap["foo" as "foo" | "baz"] : boolean +>strMap["foo" as "foo" | "baz"] : boolean | undefined >strMap : { [s: string]: boolean; } >"foo" as "foo" | "baz" : "foo" | "baz" >"foo" : "foo" const e8: boolean = strMap[NumericEnum1.A]; >e8 : boolean ->strMap[NumericEnum1.A] : boolean +>strMap[NumericEnum1.A] : boolean | undefined >strMap : { [s: string]: boolean; } >NumericEnum1.A : NumericEnum1.A >NumericEnum1 : typeof NumericEnum1 @@ -89,7 +89,7 @@ const e8: boolean = strMap[NumericEnum1.A]; const e9: boolean = strMap[NumericEnum2.A]; >e9 : boolean ->strMap[NumericEnum2.A] : boolean +>strMap[NumericEnum2.A] : boolean | undefined >strMap : { [s: string]: boolean; } >NumericEnum2.A : NumericEnum2.A >NumericEnum2 : typeof NumericEnum2 @@ -97,7 +97,7 @@ const e9: boolean = strMap[NumericEnum2.A]; const e10: boolean = strMap[StringEnum1.A]; >e10 : boolean ->strMap[StringEnum1.A] : boolean +>strMap[StringEnum1.A] : boolean | undefined >strMap : { [s: string]: boolean; } >StringEnum1.A : StringEnum1.A >StringEnum1 : typeof StringEnum1 @@ -105,7 +105,7 @@ const e10: boolean = strMap[StringEnum1.A]; const e11: boolean = strMap[StringEnum1.A as StringEnum1]; >e11 : boolean ->strMap[StringEnum1.A as StringEnum1] : boolean +>strMap[StringEnum1.A as StringEnum1] : boolean | undefined >strMap : { [s: string]: boolean; } >StringEnum1.A as StringEnum1 : StringEnum1 >StringEnum1.A : StringEnum1.A @@ -114,7 +114,7 @@ const e11: boolean = strMap[StringEnum1.A as StringEnum1]; const e12: boolean = strMap[NumericEnum1.A as NumericEnum1]; >e12 : boolean ->strMap[NumericEnum1.A as NumericEnum1] : boolean +>strMap[NumericEnum1.A as NumericEnum1] : boolean | undefined >strMap : { [s: string]: boolean; } >NumericEnum1.A as NumericEnum1 : NumericEnum1 >NumericEnum1.A : NumericEnum1.A @@ -123,7 +123,7 @@ const e12: boolean = strMap[NumericEnum1.A as NumericEnum1]; const e13: boolean = strMap[NumericEnum2.A as NumericEnum2]; >e13 : boolean ->strMap[NumericEnum2.A as NumericEnum2] : boolean +>strMap[NumericEnum2.A as NumericEnum2] : boolean | undefined >strMap : { [s: string]: boolean; } >NumericEnum2.A as NumericEnum2 : NumericEnum2 >NumericEnum2.A : NumericEnum2.A @@ -132,7 +132,7 @@ const e13: boolean = strMap[NumericEnum2.A as NumericEnum2]; const e14: boolean = strMap[null as any]; >e14 : boolean ->strMap[null as any] : boolean +>strMap[null as any] : boolean | undefined >strMap : { [s: string]: boolean; } >null as any : any >null : null @@ -140,7 +140,7 @@ const e14: boolean = strMap[null as any]; // Should be OK const ok1: boolean | undefined = strMap["foo"]; >ok1 : boolean | undefined ->strMap["foo"] : boolean +>strMap["foo"] : boolean | undefined >strMap : { [s: string]: boolean; } >"foo" : "foo" @@ -208,27 +208,27 @@ declare const numMap: { [s: number]: boolean }; // All of these should be ok const num_ok1: boolean = numMap[0]; >num_ok1 : boolean ->numMap[0] : boolean +>numMap[0] : boolean | undefined >numMap : { [s: number]: boolean; } >0 : 0 const num_ok2: boolean = numMap[0 as number]; >num_ok2 : boolean ->numMap[0 as number] : boolean +>numMap[0 as number] : boolean | undefined >numMap : { [s: number]: boolean; } >0 as number : number >0 : 0 const num_ok3: boolean = numMap[0 as 0 | 1]; >num_ok3 : boolean ->numMap[0 as 0 | 1] : boolean +>numMap[0 as 0 | 1] : boolean | undefined >numMap : { [s: number]: boolean; } >0 as 0 | 1 : 0 | 1 >0 : 0 const num_ok4: boolean = numMap[NumericEnum1.A]; >num_ok4 : boolean ->numMap[NumericEnum1.A] : boolean +>numMap[NumericEnum1.A] : boolean | undefined >numMap : { [s: number]: boolean; } >NumericEnum1.A : NumericEnum1.A >NumericEnum1 : typeof NumericEnum1 @@ -236,7 +236,7 @@ const num_ok4: boolean = numMap[NumericEnum1.A]; const num_ok5: boolean = numMap[NumericEnum2.A]; >num_ok5 : boolean ->numMap[NumericEnum2.A] : boolean +>numMap[NumericEnum2.A] : boolean | undefined >numMap : { [s: number]: boolean; } >NumericEnum2.A : NumericEnum2.A >NumericEnum2 : typeof NumericEnum2 @@ -250,7 +250,7 @@ function generic1(arg: T): boolean { // Should error return arg["blah"]; ->arg["blah"] : boolean +>arg["blah"] : boolean | undefined >arg : T >"blah" : "blah" } @@ -262,7 +262,7 @@ function generic2(arg: T): boolean { // Should OK return arg["blah"]!; >arg["blah"]! : boolean ->arg["blah"] : boolean +>arg["blah"] : boolean | undefined >arg : T >"blah" : "blah" } @@ -272,7 +272,7 @@ function generic3(arg: T): boolean { // Should error return strMap[arg]; ->strMap[arg] : boolean +>strMap[arg] : boolean | undefined >strMap : { [s: string]: boolean; } >arg : T } @@ -303,7 +303,7 @@ let yy = "y"; >"y" : "y" obj1[yy]; ->obj1[yy] : string | number +>obj1[yy] : string | number | undefined >obj1 : { [key: string]: string | number; x: string; y: number; } >yy : string @@ -312,7 +312,7 @@ let z = "z"; >"z" : "z" obj1[z]; ->obj1[z] : string | number +>obj1[z] : string | number | undefined >obj1 : { [key: string]: string | number; x: string; y: number; } >z : string @@ -325,7 +325,7 @@ declare const strMapUnion: { [s: string]: boolean } | { [s: string]: number }; // Should error const f1: boolean | number = strMapUnion["foo"]; >f1 : number | boolean ->strMapUnion["foo"] : number | boolean +>strMapUnion["foo"] : number | boolean | undefined >strMapUnion : { [s: string]: boolean; } | { [s: string]: number; } >"foo" : "foo" diff --git a/tests/baselines/reference/noUncheckedIndexedAccessDestructuring.errors.txt b/tests/baselines/reference/noUncheckedIndexedAccessDestructuring.errors.txt index dfe57451edc..cc29a879dee 100644 --- a/tests/baselines/reference/noUncheckedIndexedAccessDestructuring.errors.txt +++ b/tests/baselines/reference/noUncheckedIndexedAccessDestructuring.errors.txt @@ -1,8 +1,12 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(12,9): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'string'. tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(16,9): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'string'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(50,2): error TS2322: Type 'string | undefined' is not assignable to type 'string'. + Type 'undefined' is not assignable to type 'string'. +tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(59,8): error TS2322: Type 'number | undefined' is not assignable to type 'number'. + Type 'undefined' is not assignable to type 'number'. -==== tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts (2 errors) ==== +==== tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts (4 errors) ==== declare const strArray: string[]; declare const strStrTuple: [string, string]; @@ -57,6 +61,9 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(16,9): // Assignment forms [target_string] = strArray; // Should error + ~~~~~~~~~~~~~ +!!! error TS2322: Type 'string | undefined' is not assignable to type 'string'. +!!! error TS2322: Type 'undefined' is not assignable to type 'string'. [target_string_undef] = strArray; // Should OK [,,, ...target_string_arr] = strArray; // Should OK @@ -66,5 +73,8 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccessDestructuring.ts(16,9): let q: number; ({ q } = numMapPoint); // Should error + ~ +!!! error TS2322: Type 'number | undefined' is not assignable to type 'number'. +!!! error TS2322: Type 'undefined' is not assignable to type 'number'. } \ No newline at end of file diff --git a/tests/baselines/reference/noUncheckedIndexedAccessDestructuring.types b/tests/baselines/reference/noUncheckedIndexedAccessDestructuring.types index 5b28543d0c5..9d3dca24c5d 100644 --- a/tests/baselines/reference/noUncheckedIndexedAccessDestructuring.types +++ b/tests/baselines/reference/noUncheckedIndexedAccessDestructuring.types @@ -9,7 +9,7 @@ declare const strStrTuple: [string, string]; // Destructuring from a simple array -> include undefined const [s1] = strArray; ->s1 : string +>s1 : string | undefined >strArray : string[] s1.toString(); // Should error, s1 possibly undefined @@ -51,7 +51,7 @@ declare const strMap: { [s: string]: string }; >s : string const { t1 } = strMap; ->t1 : string +>t1 : string | undefined >strMap : { [s: string]: string; } t1.toString(); // Should error, t1 possibly undefined @@ -82,7 +82,7 @@ declare const numMapPoint: { x: number, y: number} & { [s: string]: number }; const { x, y, z } = numMapPoint; >x : number >y : number ->z : number +>z : number | undefined >numMapPoint : { x: number; y: number; } & { [s: string]: number; } x.toFixed(); // Should OK