|
1 |
| -tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(3,3): error TS2412: Property '"1"' of type 'string' is not assignable to numeric index type 'number'. |
2 |
| -tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(4,3): error TS2412: Property '"-1"' of type 'string' is not assignable to numeric index type 'number'. |
3 |
| -tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(5,3): error TS2412: Property '"+1"' of type 'string' is not assignable to numeric index type 'number'. |
4 |
| - |
5 |
| - |
6 |
| -==== tests/cases/compiler/propertiesAndIndexersForNumericNames.ts (3 errors) ==== |
7 |
| - class C { |
8 |
| - [i: number]: number; |
9 |
| - public "1": string = "number"; // Error |
10 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
11 |
| -!!! error TS2412: Property '"1"' of type 'string' is not assignable to numeric index type 'number'. |
12 |
| - public "-1": string = "negative number"; // Error |
13 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
14 |
| -!!! error TS2412: Property '"-1"' of type 'string' is not assignable to numeric index type 'number'. |
15 |
| - public "+1": string = "positive number (for the paranoid)"; // Error |
16 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
17 |
| -!!! error TS2412: Property '"+1"' of type 'string' is not assignable to numeric index type 'number'. |
18 |
| - |
19 |
| - public " 1": string = "leading space"; // No error |
20 |
| - public "1 ": string = "trailing space"; // No error |
21 |
| - public "": string = "no nothing"; // No error |
22 |
| - public " ": string = "just space"; // No error |
23 |
| - public "1 0 1": string = "several numbers and spaces"; // No error |
24 |
| - public "NaN": string = "not a number"; // No error |
25 |
| - public "-NaN": string = "not a negative number"; // No error |
26 |
| - public "+Infinity": string = "A gillion"; // No error |
27 |
| - public "-Infinity": string = "Negative-a-gillion"; // No error |
28 |
| - } |
| 1 | +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(6,5): error TS2412: Property '"1"' of type 'string' is not assignable to numeric index type 'number'. |
| 2 | +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(7,5): error TS2412: Property '"-1"' of type 'string' is not assignable to numeric index type 'number'. |
| 3 | +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(8,5): error TS2412: Property '"-2.5"' of type 'string' is not assignable to numeric index type 'number'. |
| 4 | +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(9,5): error TS2412: Property '"3.141592"' of type 'string' is not assignable to numeric index type 'number'. |
| 5 | +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(10,5): error TS2412: Property '"1.2e-20"' of type 'string' is not assignable to numeric index type 'number'. |
| 6 | + |
| 7 | + |
| 8 | +==== tests/cases/compiler/propertiesAndIndexersForNumericNames.ts (5 errors) ==== |
| 9 | + class C { |
| 10 | + [i: number]: number; |
| 11 | + |
| 12 | + // These all have numeric names; they should error |
| 13 | + // because their types are not compatible with the numeric indexer. |
| 14 | + public "1": string = "number"; // Error |
| 15 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 16 | +!!! error TS2412: Property '"1"' of type 'string' is not assignable to numeric index type 'number'. |
| 17 | + public "-1": string = "negative number"; // Error |
| 18 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 19 | +!!! error TS2412: Property '"-1"' of type 'string' is not assignable to numeric index type 'number'. |
| 20 | + public "-2.5": string = "negative number"; // Error |
| 21 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 22 | +!!! error TS2412: Property '"-2.5"' of type 'string' is not assignable to numeric index type 'number'. |
| 23 | + public "3.141592": string = "pi-sitive number"; // Error |
| 24 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 25 | +!!! error TS2412: Property '"3.141592"' of type 'string' is not assignable to numeric index type 'number'. |
| 26 | + public "1.2e-20": string = "really small number"; // Error |
| 27 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 28 | +!!! error TS2412: Property '"1.2e-20"' of type 'string' is not assignable to numeric index type 'number'. |
| 29 | + |
| 30 | + // These all have *partially* numeric names, |
| 31 | + // but should really be treated as plain string literals. |
| 32 | + public " 1": string = "leading space"; // No error |
| 33 | + public "1 ": string = "trailing space"; // No error |
| 34 | + public "": string = "no nothing"; // No error |
| 35 | + public " ": string = "just space"; // No error |
| 36 | + public "1 0 1": string = "several numbers and spaces"; // No error |
| 37 | + public "NaN": string = "not a number"; // No error |
| 38 | + public "-NaN": string = "not a negative number"; // No error |
| 39 | + public "hunter2": string = "not a password"; // No error |
| 40 | + public "+Infinity": string = "A gillion"; // No error |
| 41 | + public "-Infinity": string = "Negative-a-gillion"; // No error |
| 42 | + |
| 43 | + // These fall into the above category, however, they are "trickier"; |
| 44 | + // these all are *scanned* as numeric literals, but they are not written in |
| 45 | + // "canonical" numeric representations. |
| 46 | + public "+1": string = "positive number (for the paranoid)"; // No error |
| 47 | + public "1e0": string = "just one"; // No error |
| 48 | + public "-0e0": string = "just zero"; // No error |
| 49 | + public "0xF00D": string = "hex food"; // No error |
| 50 | + public "0xBEEF": string = "hex beef"; // No error |
| 51 | + public "0123": string = "oct 83"; // No error |
| 52 | + public "0.000000000000000000012": string = "should've been in exponential form"; // No error |
| 53 | + } |
29 | 54 |
|
0 commit comments