25 lines
No EOL
1.4 KiB
Text
25 lines
No EOL
1.4 KiB
Text
tests/cases/compiler/genericReduce.ts(6,4): error TS2339: Property 'x' does not exist on type 'number'.
|
|
tests/cases/compiler/genericReduce.ts(8,4): error TS2339: Property 'x' does not exist on type 'number'.
|
|
tests/cases/compiler/genericReduce.ts(12,4): error TS2339: Property 'toExponential' does not exist on type 'string'.
|
|
|
|
|
|
==== tests/cases/compiler/genericReduce.ts (3 errors) ====
|
|
var a = ["An", "array", "of", "strings"];
|
|
var b = a.map(s => s.length);
|
|
var n1 = b.reduce((x, y) => x + y);
|
|
var n2 = b.reduceRight((x, y) => x + y);
|
|
|
|
n1.x = "fail"; // should error, as 'n1' should be type 'number', not 'any'.
|
|
~
|
|
!!! error TS2339: Property 'x' does not exist on type 'number'.
|
|
n1.toExponential(2); // should not error if 'n1' is correctly number.
|
|
n2.x = "fail"; // should error, as 'n2' should be type 'number', not 'any'.
|
|
~
|
|
!!! error TS2339: Property 'x' does not exist on type 'number'.
|
|
n2.toExponential(2); // should not error if 'n2' is correctly number.
|
|
|
|
var n3 = b.reduce<string>( (x, y) => x + y, ""); // Initial value is of type string
|
|
n3.toExponential(2); // should error if 'n3' is correctly type 'string'
|
|
~~~~~~~~~~~~~
|
|
!!! error TS2339: Property 'toExponential' does not exist on type 'string'.
|
|
n3.charAt(0); // should not error if 'n3' is correctly type 'string' |