File: genericCallWithFunctionTypedArguments2.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 (145 lines) | stat: -rw-r--r-- 2,893 bytes parent folder | download
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts ===
// Generic functions used as arguments for function typed parameters are not used to make inferences from
// Using construct signature arguments, no errors expected

function foo<T>(x: new(a: T) => T) {
>foo : <T>(x: new (a: T) => T) => T
>x : new (a: T) => T
>a : T

    return new x(null);
>new x(null) : T
>x : new (a: T) => T
>null : null
}

interface I {
    new <T>(x: T): T;
>x : T
}
interface I2<T> {
    new (x: T): T;
>x : T
}
var i: I;
>i : I

var i2: I2<string>;
>i2 : I2<string>

var a: {
>a : new <T>(x: T) => T

    new <T>(x: T): T;
>x : T
}

var r = foo(i); // any
>r : {}
>foo(i) : {}
>foo : <T>(x: new (a: T) => T) => T
>i : I

var r2 = foo<string>(i); // string 
>r2 : string
>foo<string>(i) : string
>foo : <T>(x: new (a: T) => T) => T
>i : I

var r3 = foo(i2); // string
>r3 : string
>foo(i2) : string
>foo : <T>(x: new (a: T) => T) => T
>i2 : I2<string>

var r3b = foo(a); // any
>r3b : {}
>foo(a) : {}
>foo : <T>(x: new (a: T) => T) => T
>a : new <T>(x: T) => T

function foo2<T, U>(x: T, cb: new(a: T) => U) {
>foo2 : <T, U>(x: T, cb: new (a: T) => U) => U
>x : T
>cb : new (a: T) => U
>a : T

    return new cb(x);
>new cb(x) : U
>cb : new (a: T) => U
>x : T
}

var r4 = foo2(1, i2); // error
>r4 : any
>foo2(1, i2) : any
>foo2 : <T, U>(x: T, cb: new (a: T) => U) => U
>1 : 1
>i2 : I2<string>

var r4b = foo2(1, a); // any
>r4b : {}
>foo2(1, a) : {}
>foo2 : <T, U>(x: T, cb: new (a: T) => U) => U
>1 : 1
>a : new <T>(x: T) => T

var r5 = foo2(1, i); // any
>r5 : {}
>foo2(1, i) : {}
>foo2 : <T, U>(x: T, cb: new (a: T) => U) => U
>1 : 1
>i : I

var r6 = foo2<string, string>('', i2); // string
>r6 : string
>foo2<string, string>('', i2) : string
>foo2 : <T, U>(x: T, cb: new (a: T) => U) => U
>'' : ""
>i2 : I2<string>

function foo3<T, U>(x: T, cb: new(a: T) => U, y: U) {
>foo3 : <T, U>(x: T, cb: new (a: T) => U, y: U) => U
>x : T
>cb : new (a: T) => U
>a : T
>y : U

    return new cb(x);
>new cb(x) : U
>cb : new (a: T) => U
>x : T
}

var r7 = foo3(null, i, ''); // any
>r7 : {}
>foo3(null, i, '') : {}
>foo3 : <T, U>(x: T, cb: new (a: T) => U, y: U) => U
>null : null
>i : I
>'' : ""

var r7b = foo3(null, a, ''); // any
>r7b : {}
>foo3(null, a, '') : {}
>foo3 : <T, U>(x: T, cb: new (a: T) => U, y: U) => U
>null : null
>a : new <T>(x: T) => T
>'' : ""

var r8 = foo3(1, i2, 1); // error
>r8 : any
>foo3(1, i2, 1) : any
>foo3 : <T, U>(x: T, cb: new (a: T) => U, y: U) => U
>1 : 1
>i2 : I2<string>
>1 : 1

var r9 = foo3<string, string>('', i2, ''); // string
>r9 : string
>foo3<string, string>('', i2, '') : string
>foo3 : <T, U>(x: T, cb: new (a: T) => U, y: U) => U
>'' : ""
>i2 : I2<string>
>'' : ""