File: genericCallWithConstraintsTypeArgumentInference2.js

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 (25 lines) | stat: -rw-r--r-- 723 bytes parent folder | download | duplicates (7)
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
//// [genericCallWithConstraintsTypeArgumentInference2.ts]
// Generic call with parameters of T and U, U extends T, no parameter of type U

function foo<T, U extends T>(t: T) {
    var u: U;
    return u;
}

var r = foo(1); // ok
var r2 = foo(null); // {}
var r3 = foo(new Object()); // {}
var r4 = foo<Date, Date>(1); // error
var r5 = foo<Date, Date>(new Date()); // no error

//// [genericCallWithConstraintsTypeArgumentInference2.js]
// Generic call with parameters of T and U, U extends T, no parameter of type U
function foo(t) {
    var u;
    return u;
}
var r = foo(1); // ok
var r2 = foo(null); // {}
var r3 = foo(new Object()); // {}
var r4 = foo(1); // error
var r5 = foo(new Date()); // no error