mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fix incorrect name of index signature flag in implementation (#40541)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -5783,7 +5783,7 @@ namespace ts {
|
||||
assumeChangesOnlyAffectDirectDependencies?: boolean;
|
||||
noLib?: boolean;
|
||||
noResolve?: boolean;
|
||||
noUncheckedIndexSignatures?: boolean;
|
||||
noUncheckedIndexedAccess?: boolean;
|
||||
out?: string;
|
||||
outDir?: string;
|
||||
outFile?: string;
|
||||
|
||||
+1
-1
@@ -2841,7 +2841,7 @@ declare namespace ts {
|
||||
assumeChangesOnlyAffectDirectDependencies?: boolean;
|
||||
noLib?: boolean;
|
||||
noResolve?: boolean;
|
||||
noUncheckedIndexSignatures?: boolean;
|
||||
noUncheckedIndexedAccess?: boolean;
|
||||
out?: string;
|
||||
outDir?: string;
|
||||
outFile?: string;
|
||||
|
||||
+1
-1
@@ -2841,7 +2841,7 @@ declare namespace ts {
|
||||
assumeChangesOnlyAffectDirectDependencies?: boolean;
|
||||
noLib?: boolean;
|
||||
noResolve?: boolean;
|
||||
noUncheckedIndexSignatures?: boolean;
|
||||
noUncheckedIndexedAccess?: boolean;
|
||||
out?: string;
|
||||
outDir?: string;
|
||||
outFile?: string;
|
||||
|
||||
@@ -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<T extends boolean> = any;
|
||||
// Validate CheckBooleanOnly works - should error
|
||||
type T_ERR1 = CheckBooleanOnly<boolean | undefined>;
|
||||
@@ -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<T extends { [s: string]: boolean }>(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<T extends { [s: string]: boolean }>(arg: T): boolean {
|
||||
// Should OK
|
||||
@@ -82,6 +181,9 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(85,1): error TS2322
|
||||
function generic3<T extends string>(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;
|
||||
|
||||
@@ -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<T extends { [s: string]: boolean }>(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<T extends { [s: string]: boolean }>(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<T extends string>(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"
|
||||
|
||||
|
||||
@@ -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'.
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user