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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
=== tests/cases/compiler/strictFunctionTypes1.ts ===
declare function f1<T>(f1: (x: T) => void, f2: (x: T) => void): (x: T) => void;
>f1 : <T>(f1: (x: T) => void, f2: (x: T) => void) => (x: T) => void
>f1 : (x: T) => void
>x : T
>f2 : (x: T) => void
>x : T
>x : T
declare function f2<T>(obj: T, f1: (x: T) => void, f2: (x: T) => void): T;
>f2 : <T>(obj: T, f1: (x: T) => void, f2: (x: T) => void) => T
>obj : T
>f1 : (x: T) => void
>x : T
>f2 : (x: T) => void
>x : T
declare function f3<T>(obj: T, f1: (x: T) => void, f2: (f: (x: T) => void) => void): T;
>f3 : <T>(obj: T, f1: (x: T) => void, f2: (f: (x: T) => void) => void) => T
>obj : T
>f1 : (x: T) => void
>x : T
>f2 : (f: (x: T) => void) => void
>f : (x: T) => void
>x : T
interface Func<T> { (x: T): void }
>x : T
declare function f4<T>(f1: Func<T>, f2: Func<T>): Func<T>;
>f4 : <T>(f1: Func<T>, f2: Func<T>) => Func<T>
>f1 : Func<T>
>f2 : Func<T>
declare function fo(x: Object): void;
>fo : (x: Object) => void
>x : Object
declare function fs(x: string): void;
>fs : (x: string) => void
>x : string
declare function fx(f: (x: "def") => void): void;
>fx : (f: (x: "def") => void) => void
>f : (x: "def") => void
>x : "def"
const x1 = f1(fo, fs); // (x: string) => void
>x1 : (x: string) => void
>f1(fo, fs) : (x: string) => void
>f1 : <T>(f1: (x: T) => void, f2: (x: T) => void) => (x: T) => void
>fo : (x: Object) => void
>fs : (x: string) => void
const x2 = f2("abc", fo, fs); // "abc"
>x2 : "abc"
>f2("abc", fo, fs) : "abc"
>f2 : <T>(obj: T, f1: (x: T) => void, f2: (x: T) => void) => T
>"abc" : "abc"
>fo : (x: Object) => void
>fs : (x: string) => void
const x3 = f3("abc", fo, fx); // "abc" | "def"
>x3 : "def" | "abc"
>f3("abc", fo, fx) : "def" | "abc"
>f3 : <T>(obj: T, f1: (x: T) => void, f2: (f: (x: T) => void) => void) => T
>"abc" : "abc"
>fo : (x: Object) => void
>fx : (f: (x: "def") => void) => void
const x4 = f4(fo, fs); // Func<string>
>x4 : Func<string>
>f4(fo, fs) : Func<string>
>f4 : <T>(f1: Func<T>, f2: Func<T>) => Func<T>
>fo : (x: Object) => void
>fs : (x: string) => void
declare const never: never;
>never : never
const x10 = f2(never, fo, fs); // string
>x10 : string
>f2(never, fo, fs) : string
>f2 : <T>(obj: T, f1: (x: T) => void, f2: (x: T) => void) => T
>never : never
>fo : (x: Object) => void
>fs : (x: string) => void
const x11 = f3(never, fo, fx); // "def"
>x11 : "def"
>f3(never, fo, fx) : "def"
>f3 : <T>(obj: T, f1: (x: T) => void, f2: (f: (x: T) => void) => void) => T
>never : never
>fo : (x: Object) => void
>fx : (f: (x: "def") => void) => void
// Repro from #21112
declare function foo<T>(a: ReadonlyArray<T>): T;
>foo : <T>(a: ReadonlyArray<T>) => T
>a : ReadonlyArray<T>
let x = foo([]); // never
>x : never
>foo([]) : never
>foo : <T>(a: ReadonlyArray<T>) => T
>[] : never[]
// Modified repros from #26127
interface A { a: string }
>a : string
interface B extends A { b: string }
>b : string
declare function acceptUnion(x: A | number): void;
>acceptUnion : (x: number | A) => void
>x : number | A
declare function acceptA(x: A): void;
>acceptA : (x: A) => void
>x : A
declare let a: A;
>a : A
declare let b: B;
>b : B
declare function coAndContra<T>(value: T, func: (t: T) => void): T;
>coAndContra : <T>(value: T, func: (t: T) => void) => T
>value : T
>func : (t: T) => void
>t : T
const t1: A = coAndContra(a, acceptUnion);
>t1 : A
>coAndContra(a, acceptUnion) : A
>coAndContra : <T>(value: T, func: (t: T) => void) => T
>a : A
>acceptUnion : (x: number | A) => void
const t2: B = coAndContra(b, acceptA);
>t2 : B
>coAndContra(b, acceptA) : B
>coAndContra : <T>(value: T, func: (t: T) => void) => T
>b : B
>acceptA : (x: A) => void
const t3: A = coAndContra(never, acceptA);
>t3 : A
>coAndContra(never, acceptA) : A
>coAndContra : <T>(value: T, func: (t: T) => void) => T
>never : never
>acceptA : (x: A) => void
declare function coAndContraArray<T>(value: T[], func: (t: T) => void): T[];
>coAndContraArray : <T>(value: T[], func: (t: T) => void) => T[]
>value : T[]
>func : (t: T) => void
>t : T
const t4: A[] = coAndContraArray([a], acceptUnion);
>t4 : A[]
>coAndContraArray([a], acceptUnion) : A[]
>coAndContraArray : <T>(value: T[], func: (t: T) => void) => T[]
>[a] : A[]
>a : A
>acceptUnion : (x: number | A) => void
const t5: B[] = coAndContraArray([b], acceptA);
>t5 : B[]
>coAndContraArray([b], acceptA) : B[]
>coAndContraArray : <T>(value: T[], func: (t: T) => void) => T[]
>[b] : B[]
>b : B
>acceptA : (x: A) => void
const t6: A[] = coAndContraArray([], acceptA);
>t6 : A[]
>coAndContraArray([], acceptA) : A[]
>coAndContraArray : <T>(value: T[], func: (t: T) => void) => T[]
>[] : never[]
>acceptA : (x: A) => void
|