2014-07-13 01:04:16 +02:00
|
|
|
//// [genericCallWithFunctionTypedArguments.ts]
|
|
|
|
// Generic functions used as arguments for function typed parameters are not used to make inferences from
|
|
|
|
// Using function arguments, no errors expected
|
|
|
|
|
|
|
|
function foo<T>(x: (a: T) => T) {
|
|
|
|
return x(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
var r = foo(<U>(x: U) => ''); // {}
|
|
|
|
var r2 = foo<string>(<U>(x: U) => ''); // string
|
|
|
|
var r3 = foo(x => ''); // {}
|
|
|
|
|
|
|
|
function foo2<T, U>(x: T, cb: (a: T) => U) {
|
|
|
|
return cb(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
var r4 = foo2(1, function <Z>(a: Z) { return '' }); // string, contextual signature instantiation is applied to generic functions
|
|
|
|
var r5 = foo2(1, (a) => ''); // string
|
|
|
|
var r6 = foo2<string, number>('', <Z>(a: Z) => 1);
|
|
|
|
|
|
|
|
function foo3<T, U>(x: T, cb: (a: T) => U, y: U) {
|
|
|
|
return cb(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
var r7 = foo3(1, <Z>(a: Z) => '', ''); // string
|
|
|
|
|
2014-10-10 23:41:14 +02:00
|
|
|
var r8 = foo3(1, function (a) { return '' }, 1); // error
|
2014-07-13 01:04:16 +02:00
|
|
|
var r9 = foo3<number, string>(1, (a) => '', ''); // string
|
|
|
|
|
|
|
|
function other<T, U>(t: T, u: U) {
|
2014-10-10 23:41:14 +02:00
|
|
|
var r10 = foo2(1, (x: T) => ''); // error
|
2014-07-13 01:04:16 +02:00
|
|
|
var r10 = foo2(1, (x) => ''); // string
|
|
|
|
|
2014-10-10 23:41:14 +02:00
|
|
|
var r11 = foo3(1, (x: T) => '', ''); // error
|
|
|
|
var r11b = foo3(1, (x: T) => '', 1); // error
|
|
|
|
var r12 = foo3(1, function (a) { return '' }, 1); // error
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//// [genericCallWithFunctionTypedArguments.js]
|
2014-08-14 15:21:30 +02:00
|
|
|
// Generic functions used as arguments for function typed parameters are not used to make inferences from
|
|
|
|
// Using function arguments, no errors expected
|
2014-07-13 01:04:16 +02:00
|
|
|
function foo(x) {
|
|
|
|
return x(null);
|
|
|
|
}
|
2014-08-15 22:18:54 +02:00
|
|
|
var r = foo(function (x) { return ''; }); // {}
|
|
|
|
var r2 = foo(function (x) { return ''; }); // string
|
|
|
|
var r3 = foo(function (x) { return ''; }); // {}
|
2014-07-13 01:04:16 +02:00
|
|
|
function foo2(x, cb) {
|
|
|
|
return cb(x);
|
|
|
|
}
|
2015-02-07 05:03:24 +01:00
|
|
|
var r4 = foo2(1, function (a) { return ''; }); // string, contextual signature instantiation is applied to generic functions
|
2014-08-15 22:18:54 +02:00
|
|
|
var r5 = foo2(1, function (a) { return ''; }); // string
|
2014-07-13 01:04:16 +02:00
|
|
|
var r6 = foo2('', function (a) { return 1; });
|
|
|
|
function foo3(x, cb, y) {
|
|
|
|
return cb(x);
|
|
|
|
}
|
2014-08-15 22:18:54 +02:00
|
|
|
var r7 = foo3(1, function (a) { return ''; }, ''); // string
|
2015-02-07 05:03:24 +01:00
|
|
|
var r8 = foo3(1, function (a) { return ''; }, 1); // error
|
2014-08-15 22:18:54 +02:00
|
|
|
var r9 = foo3(1, function (a) { return ''; }, ''); // string
|
2014-07-13 01:04:16 +02:00
|
|
|
function other(t, u) {
|
2014-10-10 23:41:14 +02:00
|
|
|
var r10 = foo2(1, function (x) { return ''; }); // error
|
2014-08-15 22:18:54 +02:00
|
|
|
var r10 = foo2(1, function (x) { return ''; }); // string
|
2014-10-10 23:41:14 +02:00
|
|
|
var r11 = foo3(1, function (x) { return ''; }, ''); // error
|
|
|
|
var r11b = foo3(1, function (x) { return ''; }, 1); // error
|
2015-02-07 05:03:24 +01:00
|
|
|
var r12 = foo3(1, function (a) { return ''; }, 1); // error
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|