2014-07-13 01:04:16 +02:00
//// [genericCallWithGenericSignatureArguments.ts]
// When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made,
// the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them.
function foo < T > ( a : ( x : T ) => T , b : ( x : T ) => T ) {
var r : ( x : T ) => T ;
return r ;
}
//var r1 = foo((x: number) => 1, (x: string) => ''); // error
var r1b = foo ( ( x ) => 1 , ( x ) => '' ) ; // {} => {}
var r2 = foo ( ( x : Object ) => null , ( x : string ) => '' ) ; // Object => Object
var r3 = foo ( ( x : number ) => 1 , ( x : Object ) => null ) ; // number => number
var r3ii = foo ( ( x : number ) => 1 , ( x : number ) => 1 ) ; // number => number
var a : { x : number ; y ? : number ; } ;
var b : { x : number ; z ? : number ; } ;
var r4 = foo ( ( x : typeof a ) => a , ( x : typeof b ) => b ) ; // typeof a => typeof a
var r5 = foo ( ( x : typeof b ) => b , ( x : typeof a ) => a ) ; // typeof b => typeof b
function other < T > ( x : T ) {
var r6 = foo ( ( a : T ) => a , ( b : T ) => b ) ; // T => T
var r6b = foo ( ( a ) => a , ( b ) => b ) ; // {} => {}
}
function other2 < T extends Date > ( x : T ) {
var r7 = foo ( ( a : T ) => a , ( b : T ) => b ) ; // T => T
var r7b = foo ( ( a ) => a , ( b ) => b ) ; // {} => {}
var r8 = r7 ( null ) ;
// BUG 835518
//var r9 = r7(new Date());
}
function foo2 < T extends Date > ( a : ( x : T ) => T , b : ( x : T ) => T ) {
var r : ( x : T ) => T ;
return r ;
}
function other3 < T extends RegExp > ( x : T ) {
var r8 = foo2 ( ( a : Date ) => a , ( b : Date ) => b ) ; // Date => Date
}
//// [genericCallWithGenericSignatureArguments.js]
2014-08-14 15:21:30 +02:00
// When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made,
// the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them.
2014-07-13 01:04:16 +02:00
function foo ( a , b ) {
var r ;
return r ;
}
2014-08-12 00:54:12 +02:00
//var r1 = foo((x: number) => 1, (x: string) => ''); // error
2014-08-15 22:18:54 +02:00
var r1b = foo ( function ( x ) { return 1 ; } , function ( x ) { return '' ; } ) ; // {} => {}
var r2 = foo ( function ( x ) { return null ; } , function ( x ) { return '' ; } ) ; // Object => Object
var r3 = foo ( function ( x ) { return 1 ; } , function ( x ) { return null ; } ) ; // number => number
var r3ii = foo ( function ( x ) { return 1 ; } , function ( x ) { return 1 ; } ) ; // number => number
2014-07-13 01:04:16 +02:00
var a ;
var b ;
2014-08-15 22:18:54 +02:00
var r4 = foo ( function ( x ) { return a ; } , function ( x ) { return b ; } ) ; // typeof a => typeof a
var r5 = foo ( function ( x ) { return b ; } , function ( x ) { return a ; } ) ; // typeof b => typeof b
2014-07-13 01:04:16 +02:00
function other ( x ) {
2014-08-15 22:18:54 +02:00
var r6 = foo ( function ( a ) { return a ; } , function ( b ) { return b ; } ) ; // T => T
var r6b = foo ( function ( a ) { return a ; } , function ( b ) { return b ; } ) ; // {} => {}
2014-07-13 01:04:16 +02:00
}
function other2 ( x ) {
2014-08-15 22:18:54 +02:00
var r7 = foo ( function ( a ) { return a ; } , function ( b ) { return b ; } ) ; // T => T
var r7b = foo ( function ( a ) { return a ; } , function ( b ) { return b ; } ) ; // {} => {}
2014-07-13 01:04:16 +02:00
var r8 = r7 ( null ) ;
2014-08-22 02:17:02 +02:00
// BUG 835518
//var r9 = r7(new Date());
2014-07-13 01:04:16 +02:00
}
function foo2 ( a , b ) {
var r ;
return r ;
}
function other3 ( x ) {
2014-08-15 22:18:54 +02:00
var r8 = foo2 ( function ( a ) { return a ; } , function ( b ) { return b ; } ) ; // Date => Date
2014-07-13 01:04:16 +02:00
}