2014-07-13 01:04:16 +02:00
|
|
|
//// [genericCallWithObjectTypeArgsAndConstraints5.ts]
|
|
|
|
// Generic call with constraints infering type parameter from object member properties
|
|
|
|
|
|
|
|
class C {
|
|
|
|
x: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
class D {
|
|
|
|
x: string;
|
|
|
|
y: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
function foo<T, U extends T>(t: T, t2: U) {
|
|
|
|
return (x: T) => t2;
|
|
|
|
}
|
|
|
|
|
|
|
|
var c: C;
|
|
|
|
var d: D;
|
|
|
|
var r2 = foo(d, c); // the constraints are self-referencing, no downstream error
|
|
|
|
var r9 = foo(() => 1, () => { }); // the constraints are self-referencing, no downstream error
|
|
|
|
|
|
|
|
function other<T, U extends T>() {
|
|
|
|
var r5 = foo<T, U>(c, d); // error
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//// [genericCallWithObjectTypeArgsAndConstraints5.js]
|
2014-08-14 15:42:18 +02:00
|
|
|
// Generic call with constraints infering type parameter from object member properties
|
2014-07-13 01:04:16 +02:00
|
|
|
var C = (function () {
|
|
|
|
function C() {
|
|
|
|
}
|
|
|
|
return C;
|
|
|
|
})();
|
|
|
|
var D = (function () {
|
|
|
|
function D() {
|
|
|
|
}
|
|
|
|
return D;
|
|
|
|
})();
|
|
|
|
function foo(t, t2) {
|
|
|
|
return function (x) { return t2; };
|
|
|
|
}
|
|
|
|
var c;
|
|
|
|
var d;
|
2014-08-15 22:18:54 +02:00
|
|
|
var r2 = foo(d, c); // the constraints are self-referencing, no downstream error
|
2015-02-07 03:45:09 +01:00
|
|
|
var r9 = foo(function () { return 1; }, function () { }); // the constraints are self-referencing, no downstream error
|
2014-07-13 01:04:16 +02:00
|
|
|
function other() {
|
2014-08-15 22:18:54 +02:00
|
|
|
var r5 = foo(c, d); // error
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|