1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
=== tests/cases/compiler/recursiveFunctionTypes.ts ===
function fn(): typeof fn { return 1; }
>fn : () => typeof fn
>fn : () => typeof fn
>1 : 1
var x: number = fn; // error
>x : number
>fn : () => typeof fn
var y: () => number = fn; // ok
>y : () => number
>fn : () => typeof fn
var f: () => typeof g;
>f : () => () => any
>g : () => () => any
var g: () => typeof f;
>g : () => () => any
>f : () => () => any
function f1(d: typeof f1) { }
>f1 : (d: typeof f1) => void
>d : (d: typeof f1) => void
>f1 : (d: typeof f1) => void
function f2(): typeof g2 { }
>f2 : () => () => typeof f2
>g2 : () => () => typeof g2
function g2(): typeof f2 { }
>g2 : () => () => typeof g2
>f2 : () => () => typeof f2
interface I<T> { }
function f3(): I<typeof f3> { return f3; }
>f3 : () => I<typeof f3>
>f3 : () => I<typeof f3>
>f3 : () => I<typeof f3>
var a: number = f3; // error
>a : number
>f3 : () => I<typeof f3>
class C {
>C : C
static g(t: typeof C.g){ }
>g : (t: typeof C.g) => void
>t : (t: typeof C.g) => void
>C.g : (t: typeof C.g) => void
>C : typeof C
>g : (t: typeof C.g) => void
}
C.g(3); // error
>C.g(3) : void
>C.g : (t: typeof C.g) => void
>C : typeof C
>g : (t: typeof C.g) => void
>3 : 3
var f4: () => typeof f4;
>f4 : () => any
>f4 : () => any
f4 = 3; // error
>f4 = 3 : 3
>f4 : () => any
>3 : 3
function f5() { return f5; }
>f5 : () => typeof f5
>f5 : () => typeof f5
function f6(): typeof f6;
>f6 : { (): typeof f6; (a: typeof f6): () => number; }
>f6 : { (): typeof f6; (a: typeof f6): () => number; }
function f6(a: typeof f6): () => number;
>f6 : { (): typeof f6; (a: typeof f6): () => number; }
>a : { (): typeof f6; (a: typeof f6): () => number; }
>f6 : { (): typeof f6; (a: typeof f6): () => number; }
function f6(a?: any) { return f6; }
>f6 : { (): typeof f6; (a: typeof f6): () => number; }
>a : any
>f6 : { (): typeof f6; (a: typeof f6): () => number; }
f6("", 3); // error (arity mismatch)
>f6("", 3) : any
>f6 : { (): typeof f6; (a: typeof f6): () => number; }
>"" : ""
>3 : 3
f6(""); // ok (function takes an any param)
>f6("") : any
>f6 : { (): typeof f6; (a: typeof f6): () => number; }
>"" : ""
f6(); // ok
>f6() : { (): typeof f6; (a: typeof f6): () => number; }
>f6 : { (): typeof f6; (a: typeof f6): () => number; }
declare function f7(): typeof f7;
>f7 : { (): typeof f7; (a: typeof f7): () => number; (a: number): number; (a?: typeof f7): typeof f7; }
>f7 : { (): typeof f7; (a: typeof f7): () => number; (a: number): number; (a?: typeof f7): typeof f7; }
declare function f7(a: typeof f7): () => number;
>f7 : { (): typeof f7; (a: typeof f7): () => number; (a: number): number; (a?: typeof f7): typeof f7; }
>a : { (): typeof f7; (a: typeof f7): () => number; (a: number): number; (a?: typeof f7): typeof f7; }
>f7 : { (): typeof f7; (a: typeof f7): () => number; (a: number): number; (a?: typeof f7): typeof f7; }
declare function f7(a: number): number;
>f7 : { (): typeof f7; (a: typeof f7): () => number; (a: number): number; (a?: typeof f7): typeof f7; }
>a : number
declare function f7(a?: typeof f7): typeof f7;
>f7 : { (): typeof f7; (a: typeof f7): () => number; (a: number): number; (a?: typeof f7): typeof f7; }
>a : { (): typeof f7; (a: typeof f7): () => number; (a: number): number; (a?: typeof f7): typeof f7; }
>f7 : { (): typeof f7; (a: typeof f7): () => number; (a: number): number; (a?: typeof f7): typeof f7; }
>f7 : { (): typeof f7; (a: typeof f7): () => number; (a: number): number; (a?: typeof f7): typeof f7; }
f7("", 3); // error (arity mismatch)
>f7("", 3) : any
>f7 : { (): typeof f7; (a: typeof f7): () => number; (a: number): number; (a?: typeof f7): typeof f7; }
>"" : ""
>3 : 3
f7(""); // ok (function takes an any param)
>f7("") : any
>f7 : { (): typeof f7; (a: typeof f7): () => number; (a: number): number; (a?: typeof f7): typeof f7; }
>"" : ""
f7(); // ok
>f7() : { (): typeof f7; (a: typeof f7): () => number; (a: number): number; (a?: typeof f7): typeof f7; }
>f7 : { (): typeof f7; (a: typeof f7): () => number; (a: number): number; (a?: typeof f7): typeof f7; }
|