Specifically, a numeric property is simply now any property whose name N is equal to ToString(ToNumber(N)).
69 lines
No EOL
4.9 KiB
Text
69 lines
No EOL
4.9 KiB
Text
tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(6,5): error TS2412: Property '"1"' of type 'string' is not assignable to numeric index type 'number'.
|
|
tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(7,5): error TS2412: Property '"-1"' of type 'string' is not assignable to numeric index type 'number'.
|
|
tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(8,5): error TS2412: Property '"-2.5"' of type 'string' is not assignable to numeric index type 'number'.
|
|
tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(9,5): error TS2412: Property '"3.141592"' of type 'string' is not assignable to numeric index type 'number'.
|
|
tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(10,5): error TS2412: Property '"1.2e-20"' of type 'string' is not assignable to numeric index type 'number'.
|
|
tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(11,5): error TS2412: Property '"Infinity"' of type 'string' is not assignable to numeric index type 'number'.
|
|
tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(12,5): error TS2412: Property '"-Infinity"' of type 'string' is not assignable to numeric index type 'number'.
|
|
tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(13,5): error TS2412: Property '"NaN"' of type 'string' is not assignable to numeric index type 'number'.
|
|
|
|
|
|
==== tests/cases/compiler/propertiesAndIndexersForNumericNames.ts (8 errors) ====
|
|
class C {
|
|
[i: number]: number;
|
|
|
|
// These all have numeric names; they should error
|
|
// because their types are not compatible with the numeric indexer.
|
|
public "1": string = "number"; // Error
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
!!! error TS2412: Property '"1"' of type 'string' is not assignable to numeric index type 'number'.
|
|
public "-1": string = "negative number"; // Error
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
!!! error TS2412: Property '"-1"' of type 'string' is not assignable to numeric index type 'number'.
|
|
public "-2.5": string = "negative number"; // Error
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
!!! error TS2412: Property '"-2.5"' of type 'string' is not assignable to numeric index type 'number'.
|
|
public "3.141592": string = "pi-sitive number"; // Error
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
!!! error TS2412: Property '"3.141592"' of type 'string' is not assignable to numeric index type 'number'.
|
|
public "1.2e-20": string = "really small number"; // Error
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
!!! error TS2412: Property '"1.2e-20"' of type 'string' is not assignable to numeric index type 'number'.
|
|
public "Infinity": string = "A gillion"; // Error
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
!!! error TS2412: Property '"Infinity"' of type 'string' is not assignable to numeric index type 'number'.
|
|
public "-Infinity": string = "Negative-a-gillion"; // Error
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
!!! error TS2412: Property '"-Infinity"' of type 'string' is not assignable to numeric index type 'number'.
|
|
public "NaN": string = "not a number"; // Error
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
!!! error TS2412: Property '"NaN"' of type 'string' is not assignable to numeric index type 'number'.
|
|
|
|
// These all have *partially* numeric names,
|
|
// but should really be treated as plain string literals.
|
|
public " 1": string = "leading space"; // No error
|
|
public "1 ": string = "trailing space"; // No error
|
|
public "": string = "no nothing"; // No error
|
|
public " ": string = "just space"; // No error
|
|
public "1 0 1": string = "several numbers and spaces"; // No error
|
|
public "hunter2": string = "not a password"; // No error
|
|
public "+Infinity": string = "A gillion"; // No error
|
|
public "+NaN": string = "not a positive number"; // No error
|
|
public "-NaN": string = "not a negative number"; // No error
|
|
|
|
|
|
// These fall into the above category, however, they are "trickier";
|
|
// these all are *scanned* as numeric literals, but they are not written in
|
|
// "canonical" numeric representations.
|
|
public "+1": string = "positive number (for the paranoid)"; // No error
|
|
public "1e0": string = "just one"; // No error
|
|
public "-0": string = "just zero"; // No error
|
|
public "-0e0": string = "just zero"; // No error
|
|
public "0xF00D": string = "hex food"; // No error
|
|
public "0xBEEF": string = "hex beef"; // No error
|
|
public "0123": string = "oct 83"; // No error
|
|
public "0o123": string = "explicit oct 83"; // No error
|
|
public "0b101101001010": string = "explicit binary"; // No error
|
|
public "0.000000000000000000012": string = "should've been in exponential form"; // No error
|
|
}
|
|
|