In effect this fixes #62. Also - Changes the error message for get accessors lacking return expressions. - Actually checks for return expressions instead of return statements for get-accessors. - Removes fancy quotes. - Corrects errors in the compiler caught by the new check. - Simplified `checkAndAggregateReturnTypes` by extracting it out to `visitReturnStatements`.
70 lines
No EOL
2.4 KiB
Text
70 lines
No EOL
2.4 KiB
Text
==== tests/cases/compiler/recursiveFunctionTypes.ts (12 errors) ====
|
|
function fn(): typeof fn { return 1; }
|
|
~
|
|
!!! Type 'number' is not assignable to type '() => typeof fn'.
|
|
|
|
var x: number = fn; // error
|
|
~
|
|
!!! Type '() => typeof fn' is not assignable to type 'number'.
|
|
var y: () => number = fn; // ok
|
|
~
|
|
!!! Type '() => typeof fn' is not assignable to type '() => number':
|
|
!!! Type '() => typeof fn' is not assignable to type 'number'.
|
|
|
|
var f: () => typeof g;
|
|
var g: () => typeof f;
|
|
|
|
function f1(d: typeof f1) { }
|
|
|
|
function f2(): typeof g2 { }
|
|
~~~~~~~~~
|
|
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
|
|
function g2(): typeof f2 { }
|
|
~~~~~~~~~
|
|
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
|
|
|
|
interface I<T> { }
|
|
function f3(): I<typeof f3> { return f3; }
|
|
|
|
var a: number = f3; // error
|
|
~
|
|
!!! Type '() => I<typeof f3>' is not assignable to type 'number'.
|
|
|
|
class C {
|
|
static g(t: typeof C.g){ }
|
|
}
|
|
C.g(3); // error
|
|
~~~~~~
|
|
!!! Supplied parameters do not match any signature of call target.
|
|
|
|
var f4: () => typeof f4;
|
|
f4 = 3; // error
|
|
|
|
function f5() { return f5; }
|
|
|
|
function f6(): typeof f6;
|
|
function f6(a: typeof f6): () => number;
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
!!! Overload signature is not compatible with function implementation.
|
|
function f6(a?: any) { return f6; }
|
|
|
|
f6("", 3); // error (arity mismatch)
|
|
~~~~~~~~~
|
|
!!! Supplied parameters do not match any signature of call target.
|
|
f6(""); // ok (function takes an any param)
|
|
~~~~~~
|
|
!!! Supplied parameters do not match any signature of call target.
|
|
f6(); // ok
|
|
|
|
declare function f7(): typeof f7;
|
|
declare function f7(a: typeof f7): () => number;
|
|
declare function f7(a: number): number;
|
|
declare function f7(a?: typeof f7): typeof f7;
|
|
|
|
f7("", 3); // error (arity mismatch)
|
|
~~~~~~~~~
|
|
!!! Supplied parameters do not match any signature of call target.
|
|
f7(""); // ok (function takes an any param)
|
|
~~~~~~
|
|
!!! Supplied parameters do not match any signature of call target.
|
|
f7(); // ok |