@@ -973,6 +973,68 @@ export class AssignmentTests {
973973 Expect ( util . transpileAndExecute ( code ) ) . toBe ( "foo" ) ;
974974 }
975975
976+ @TestCase ( "(this: void, s: string) => string" , "s => s" )
977+ @TestCase ( "(this: any, s: string) => string" , "s => s" )
978+ @TestCase ( "(s: string) => string" , "s => s" )
979+ @TestCase ( "(this: void, s: string) => string" , "function(s) { return s; }" )
980+ @TestCase ( "(this: any, s: string) => string" , "function(s) { return s; }" )
981+ @TestCase ( "(s: string) => string" , "function(s) { return s; }" )
982+ @Test ( "Function expression type inference in union" )
983+ public functionExpressionTypeInferenceInUnion ( funcType : string , funcExp : string ) : void {
984+ const code =
985+ `type U = string | number | (${ funcType } );
986+ const u: U = ${ funcExp } ;
987+ return (u as ${ funcType } )("foo");` ;
988+ Expect ( util . transpileAndExecute ( code ) ) . toBe ( "foo" ) ;
989+ }
990+
991+ @TestCase ( "(this: void, s: string) => string" , "s => s" )
992+ @TestCase ( "(this: any, s: string) => string" , "s => s" )
993+ @TestCase ( "(s: string) => string" , "s => s" )
994+ @TestCase ( "(this: void, s: string) => string" , "function(s) { return s; }" )
995+ @TestCase ( "(this: any, s: string) => string" , "function(s) { return s; }" )
996+ @TestCase ( "(s: string) => string" , "function(s) { return s; }" )
997+ @Test ( "Function expression type inference in as cast" )
998+ public functionExpressionTypeInferenceInAsCast ( funcType : string , funcExp : string ) : void {
999+ const code =
1000+ `const fn: ${ funcType } = (${ funcExp } ) as (${ funcType } );
1001+ return fn("foo");` ;
1002+ console . log ( code ) ;
1003+ Expect ( util . transpileAndExecute ( code ) ) . toBe ( "foo" ) ;
1004+ }
1005+
1006+ @TestCase ( "(this: void, s: string) => string" , "s => s" )
1007+ @TestCase ( "(this: any, s: string) => string" , "s => s" )
1008+ @TestCase ( "(s: string) => string" , "s => s" )
1009+ @TestCase ( "(this: void, s: string) => string" , "function(s) { return s; }" )
1010+ @TestCase ( "(this: any, s: string) => string" , "function(s) { return s; }" )
1011+ @TestCase ( "(s: string) => string" , "function(s) { return s; }" )
1012+ @Test ( "Function expression type inference in type assertion" )
1013+ public functionExpressionTypeInferenceInTypeAssert ( funcType : string , funcExp : string ) : void {
1014+ const code =
1015+ `const fn: ${ funcType } = <${ funcType } >(${ funcExp } );
1016+ return fn("foo");` ;
1017+ Expect ( util . transpileAndExecute ( code ) ) . toBe ( "foo" ) ;
1018+ }
1019+
1020+ @TestCase ( "(this: void, s: string) => string" , "s => s" )
1021+ @TestCase ( "(this: any, s: string) => string" , "s => s" )
1022+ @TestCase ( "(s: string) => string" , "s => s" )
1023+ @TestCase ( "(this: void, s: string) => string" , "function(s) { return s; }" )
1024+ @TestCase ( "(this: any, s: string) => string" , "function(s) { return s; }" )
1025+ @TestCase ( "(s: string) => string" , "function(s) { return s; }" )
1026+ @Test ( "Function expression type inference in constructor" )
1027+ public functionExpresssionTypeInferenceInConstructor ( funcType : string , funcExp : string ) : void {
1028+ const code =
1029+ `class C {
1030+ result: string;
1031+ constructor(fn: (s: string) => string) { this.result = fn("foo"); }
1032+ }
1033+ const c = new C(s => s);
1034+ return c.result;` ;
1035+ Expect ( util . transpileAndExecute ( code ) ) . toBe ( "foo" ) ;
1036+ }
1037+
9761038 @Test ( "String table access" )
9771039 public stringTableAccess ( assignType : string ) : void {
9781040 const code = `const dict : {[key:string]:any} = {};
0 commit comments