File: genericReduce.types

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (103 lines) | stat: -rw-r--r-- 4,956 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
=== tests/cases/compiler/genericReduce.ts ===
var a = ["An", "array", "of", "strings"];
>a : string[]
>["An", "array", "of", "strings"] : string[]
>"An" : "An"
>"array" : "array"
>"of" : "of"
>"strings" : "strings"

var b = a.map(s => s.length);
>b : number[]
>a.map(s => s.length) : number[]
>a.map : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
>a : string[]
>map : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
>s => s.length : (s: string) => number
>s : string
>s.length : number
>s : string
>length : number

var n1 = b.reduce((x, y) => x + y);
>n1 : number
>b.reduce((x, y) => x + y) : number
>b.reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; <U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; }
>b : number[]
>reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; <U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; }
>(x, y) => x + y : (x: number, y: number) => number
>x : number
>y : number
>x + y : number
>x : number
>y : number

var n2 = b.reduceRight((x, y) => x + y);
>n2 : number
>b.reduceRight((x, y) => x + y) : number
>b.reduceRight : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; <U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; }
>b : number[]
>reduceRight : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; <U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; }
>(x, y) => x + y : (x: number, y: number) => number
>x : number
>y : number
>x + y : number
>x : number
>y : number

n1.x = "fail";       // should error, as 'n1' should be type 'number', not 'any'.
>n1.x = "fail" : "fail"
>n1.x : any
>n1 : number
>x : any
>"fail" : "fail"

n1.toExponential(2); // should not error if 'n1' is correctly number.
>n1.toExponential(2) : string
>n1.toExponential : (fractionDigits?: number) => string
>n1 : number
>toExponential : (fractionDigits?: number) => string
>2 : 2

n2.x = "fail";       // should error, as 'n2' should be type 'number', not 'any'.
>n2.x = "fail" : "fail"
>n2.x : any
>n2 : number
>x : any
>"fail" : "fail"

n2.toExponential(2); // should not error if 'n2' is correctly number.
>n2.toExponential(2) : string
>n2.toExponential : (fractionDigits?: number) => string
>n2 : number
>toExponential : (fractionDigits?: number) => string
>2 : 2

var n3 = b.reduce<string>( (x, y) => x + y, ""); // Initial value is of type string
>n3 : string
>b.reduce<string>( (x, y) => x + y, "") : string
>b.reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; <U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; }
>b : number[]
>reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; <U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; }
>(x, y) => x + y : (x: string, y: number) => string
>x : string
>y : number
>x + y : string
>x : string
>y : number
>"" : ""

n3.toExponential(2); // should error if 'n3' is correctly type 'string'
>n3.toExponential(2) : any
>n3.toExponential : any
>n3 : string
>toExponential : any
>2 : 2

n3.charAt(0);        // should not error if 'n3' is correctly type 'string'
>n3.charAt(0) : string
>n3.charAt : (pos: number) => string
>n3 : string
>charAt : (pos: number) => string
>0 : 0