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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
|
=== tests/cases/compiler/strictFunctionTypesErrors.ts ===
export {}
declare let f1: (x: Object) => Object;
>f1 : (x: Object) => Object
>x : Object
declare let f2: (x: Object) => string;
>f2 : (x: Object) => string
>x : Object
declare let f3: (x: string) => Object;
>f3 : (x: string) => Object
>x : string
declare let f4: (x: string) => string;
>f4 : (x: string) => string
>x : string
f1 = f2; // Ok
>f1 = f2 : (x: Object) => string
>f1 : (x: Object) => Object
>f2 : (x: Object) => string
f1 = f3; // Error
>f1 = f3 : (x: string) => Object
>f1 : (x: Object) => Object
>f3 : (x: string) => Object
f1 = f4; // Error
>f1 = f4 : (x: string) => string
>f1 : (x: Object) => Object
>f4 : (x: string) => string
f2 = f1; // Error
>f2 = f1 : (x: Object) => Object
>f2 : (x: Object) => string
>f1 : (x: Object) => Object
f2 = f3; // Error
>f2 = f3 : (x: string) => Object
>f2 : (x: Object) => string
>f3 : (x: string) => Object
f2 = f4; // Error
>f2 = f4 : (x: string) => string
>f2 : (x: Object) => string
>f4 : (x: string) => string
f3 = f1; // Ok
>f3 = f1 : (x: Object) => Object
>f3 : (x: string) => Object
>f1 : (x: Object) => Object
f3 = f2; // Ok
>f3 = f2 : (x: Object) => string
>f3 : (x: string) => Object
>f2 : (x: Object) => string
f3 = f4; // Ok
>f3 = f4 : (x: string) => string
>f3 : (x: string) => Object
>f4 : (x: string) => string
f4 = f1; // Error
>f4 = f1 : (x: Object) => Object
>f4 : (x: string) => string
>f1 : (x: Object) => Object
f4 = f2; // Ok
>f4 = f2 : (x: Object) => string
>f4 : (x: string) => string
>f2 : (x: Object) => string
f4 = f3; // Error
>f4 = f3 : (x: string) => Object
>f4 : (x: string) => string
>f3 : (x: string) => Object
type Func<T, U> = (x: T) => U;
>Func : Func<T, U>
>x : T
declare let g1: Func<Object, Object>;
>g1 : Func<Object, Object>
declare let g2: Func<Object, string>;
>g2 : Func<Object, string>
declare let g3: Func<string, Object>;
>g3 : Func<string, Object>
declare let g4: Func<string, string>;
>g4 : Func<string, string>
g1 = g2; // Ok
>g1 = g2 : Func<Object, string>
>g1 : Func<Object, Object>
>g2 : Func<Object, string>
g1 = g3; // Error
>g1 = g3 : Func<string, Object>
>g1 : Func<Object, Object>
>g3 : Func<string, Object>
g1 = g4; // Error
>g1 = g4 : Func<string, string>
>g1 : Func<Object, Object>
>g4 : Func<string, string>
g2 = g1; // Error
>g2 = g1 : Func<Object, Object>
>g2 : Func<Object, string>
>g1 : Func<Object, Object>
g2 = g3; // Error
>g2 = g3 : Func<string, Object>
>g2 : Func<Object, string>
>g3 : Func<string, Object>
g2 = g4; // Error
>g2 = g4 : Func<string, string>
>g2 : Func<Object, string>
>g4 : Func<string, string>
g3 = g1; // Ok
>g3 = g1 : Func<Object, Object>
>g3 : Func<string, Object>
>g1 : Func<Object, Object>
g3 = g2; // Ok
>g3 = g2 : Func<Object, string>
>g3 : Func<string, Object>
>g2 : Func<Object, string>
g3 = g4; // Ok
>g3 = g4 : Func<string, string>
>g3 : Func<string, Object>
>g4 : Func<string, string>
g4 = g1; // Error
>g4 = g1 : Func<Object, Object>
>g4 : Func<string, string>
>g1 : Func<Object, Object>
g4 = g2; // Ok
>g4 = g2 : Func<Object, string>
>g4 : Func<string, string>
>g2 : Func<Object, string>
g4 = g3; // Error
>g4 = g3 : Func<string, Object>
>g4 : Func<string, string>
>g3 : Func<string, Object>
declare let h1: Func<Func<Object, void>, Object>;
>h1 : Func<Func<Object, void>, Object>
declare let h2: Func<Func<Object, void>, string>;
>h2 : Func<Func<Object, void>, string>
declare let h3: Func<Func<string, void>, Object>;
>h3 : Func<Func<string, void>, Object>
declare let h4: Func<Func<string, void>, string>;
>h4 : Func<Func<string, void>, string>
h1 = h2; // Ok
>h1 = h2 : Func<Func<Object, void>, string>
>h1 : Func<Func<Object, void>, Object>
>h2 : Func<Func<Object, void>, string>
h1 = h3; // Ok
>h1 = h3 : Func<Func<string, void>, Object>
>h1 : Func<Func<Object, void>, Object>
>h3 : Func<Func<string, void>, Object>
h1 = h4; // Ok
>h1 = h4 : Func<Func<string, void>, string>
>h1 : Func<Func<Object, void>, Object>
>h4 : Func<Func<string, void>, string>
h2 = h1; // Error
>h2 = h1 : Func<Func<Object, void>, Object>
>h2 : Func<Func<Object, void>, string>
>h1 : Func<Func<Object, void>, Object>
h2 = h3; // Error
>h2 = h3 : Func<Func<string, void>, Object>
>h2 : Func<Func<Object, void>, string>
>h3 : Func<Func<string, void>, Object>
h2 = h4; // Ok
>h2 = h4 : Func<Func<string, void>, string>
>h2 : Func<Func<Object, void>, string>
>h4 : Func<Func<string, void>, string>
h3 = h1; // Error
>h3 = h1 : Func<Func<Object, void>, Object>
>h3 : Func<Func<string, void>, Object>
>h1 : Func<Func<Object, void>, Object>
h3 = h2; // Error
>h3 = h2 : Func<Func<Object, void>, string>
>h3 : Func<Func<string, void>, Object>
>h2 : Func<Func<Object, void>, string>
h3 = h4; // Ok
>h3 = h4 : Func<Func<string, void>, string>
>h3 : Func<Func<string, void>, Object>
>h4 : Func<Func<string, void>, string>
h4 = h1; // Error
>h4 = h1 : Func<Func<Object, void>, Object>
>h4 : Func<Func<string, void>, string>
>h1 : Func<Func<Object, void>, Object>
h4 = h2; // Error
>h4 = h2 : Func<Func<Object, void>, string>
>h4 : Func<Func<string, void>, string>
>h2 : Func<Func<Object, void>, string>
h4 = h3; // Error
>h4 = h3 : Func<Func<string, void>, Object>
>h4 : Func<Func<string, void>, string>
>h3 : Func<Func<string, void>, Object>
declare let i1: Func<Object, Func<Object, void>>;
>i1 : Func<Object, Func<Object, void>>
declare let i2: Func<Object, Func<string, void>>;
>i2 : Func<Object, Func<string, void>>
declare let i3: Func<string, Func<Object, void>>;
>i3 : Func<string, Func<Object, void>>
declare let i4: Func<string, Func<string, void>>;
>i4 : Func<string, Func<string, void>>
i1 = i2; // Error
>i1 = i2 : Func<Object, Func<string, void>>
>i1 : Func<Object, Func<Object, void>>
>i2 : Func<Object, Func<string, void>>
i1 = i3; // Error
>i1 = i3 : Func<string, Func<Object, void>>
>i1 : Func<Object, Func<Object, void>>
>i3 : Func<string, Func<Object, void>>
i1 = i4; // Error
>i1 = i4 : Func<string, Func<string, void>>
>i1 : Func<Object, Func<Object, void>>
>i4 : Func<string, Func<string, void>>
i2 = i1; // Ok
>i2 = i1 : Func<Object, Func<Object, void>>
>i2 : Func<Object, Func<string, void>>
>i1 : Func<Object, Func<Object, void>>
i2 = i3; // Error
>i2 = i3 : Func<string, Func<Object, void>>
>i2 : Func<Object, Func<string, void>>
>i3 : Func<string, Func<Object, void>>
i2 = i4; // Error
>i2 = i4 : Func<string, Func<string, void>>
>i2 : Func<Object, Func<string, void>>
>i4 : Func<string, Func<string, void>>
i3 = i1; // Ok
>i3 = i1 : Func<Object, Func<Object, void>>
>i3 : Func<string, Func<Object, void>>
>i1 : Func<Object, Func<Object, void>>
i3 = i2; // Error
>i3 = i2 : Func<Object, Func<string, void>>
>i3 : Func<string, Func<Object, void>>
>i2 : Func<Object, Func<string, void>>
i3 = i4; // Error
>i3 = i4 : Func<string, Func<string, void>>
>i3 : Func<string, Func<Object, void>>
>i4 : Func<string, Func<string, void>>
i4 = i1; // Ok
>i4 = i1 : Func<Object, Func<Object, void>>
>i4 : Func<string, Func<string, void>>
>i1 : Func<Object, Func<Object, void>>
i4 = i2; // Ok
>i4 = i2 : Func<Object, Func<string, void>>
>i4 : Func<string, Func<string, void>>
>i2 : Func<Object, Func<string, void>>
i4 = i3; // Ok
>i4 = i3 : Func<string, Func<Object, void>>
>i4 : Func<string, Func<string, void>>
>i3 : Func<string, Func<Object, void>>
interface Animal { animal: void }
>animal : void
interface Dog extends Animal { dog: void }
>dog : void
interface Cat extends Animal { cat: void }
>cat : void
interface Comparer1<T> {
compare(a: T, b: T): number;
>compare : (a: T, b: T) => number
>a : T
>b : T
}
declare let animalComparer1: Comparer1<Animal>;
>animalComparer1 : Comparer1<Animal>
declare let dogComparer1: Comparer1<Dog>;
>dogComparer1 : Comparer1<Dog>
animalComparer1 = dogComparer1; // Ok
>animalComparer1 = dogComparer1 : Comparer1<Dog>
>animalComparer1 : Comparer1<Animal>
>dogComparer1 : Comparer1<Dog>
dogComparer1 = animalComparer1; // Ok
>dogComparer1 = animalComparer1 : Comparer1<Animal>
>dogComparer1 : Comparer1<Dog>
>animalComparer1 : Comparer1<Animal>
interface Comparer2<T> {
compare: (a: T, b: T) => number;
>compare : (a: T, b: T) => number
>a : T
>b : T
}
declare let animalComparer2: Comparer2<Animal>;
>animalComparer2 : Comparer2<Animal>
declare let dogComparer2: Comparer2<Dog>;
>dogComparer2 : Comparer2<Dog>
animalComparer2 = dogComparer2; // Error
>animalComparer2 = dogComparer2 : Comparer2<Dog>
>animalComparer2 : Comparer2<Animal>
>dogComparer2 : Comparer2<Dog>
dogComparer2 = animalComparer2; // Ok
>dogComparer2 = animalComparer2 : Comparer2<Animal>
>dogComparer2 : Comparer2<Dog>
>animalComparer2 : Comparer2<Animal>
// Crate<T> is invariant in --strictFunctionTypes mode
interface Crate<T> {
item: T;
>item : T
onSetItem: (item: T) => void;
>onSetItem : (item: T) => void
>item : T
}
declare let animalCrate: Crate<Animal>;
>animalCrate : Crate<Animal>
declare let dogCrate: Crate<Dog>;
>dogCrate : Crate<Dog>
// Errors below should elaborate the reason for invariance
animalCrate = dogCrate; // Error
>animalCrate = dogCrate : Crate<Dog>
>animalCrate : Crate<Animal>
>dogCrate : Crate<Dog>
dogCrate = animalCrate; // Error
>dogCrate = animalCrate : Crate<Animal>
>dogCrate : Crate<Dog>
>animalCrate : Crate<Animal>
// Verify that callback parameters are strictly checked
declare let fc1: (f: (x: Animal) => Animal) => void;
>fc1 : (f: (x: Animal) => Animal) => void
>f : (x: Animal) => Animal
>x : Animal
declare let fc2: (f: (x: Dog) => Dog) => void;
>fc2 : (f: (x: Dog) => Dog) => void
>f : (x: Dog) => Dog
>x : Dog
fc1 = fc2; // Error
>fc1 = fc2 : (f: (x: Dog) => Dog) => void
>fc1 : (f: (x: Animal) => Animal) => void
>fc2 : (f: (x: Dog) => Dog) => void
fc2 = fc1; // Error
>fc2 = fc1 : (f: (x: Animal) => Animal) => void
>fc2 : (f: (x: Dog) => Dog) => void
>fc1 : (f: (x: Animal) => Animal) => void
// Verify that callback parameters aren't loosely checked when types
// originate in method declarations
namespace n1 {
>n1 : typeof n1
class Foo {
>Foo : Foo
static f1(x: Animal): Animal { throw "wat"; }
>f1 : (x: Animal) => Animal
>x : Animal
>"wat" : "wat"
static f2(x: Dog): Animal { throw "wat"; };
>f2 : (x: Dog) => Animal
>x : Dog
>"wat" : "wat"
}
declare let f1: (cb: typeof Foo.f1) => void;
>f1 : (cb: (x: Animal) => Animal) => void
>cb : (x: Animal) => Animal
>Foo.f1 : (x: Animal) => Animal
>Foo : typeof Foo
>f1 : (x: Animal) => Animal
declare let f2: (cb: typeof Foo.f2) => void;
>f2 : (cb: (x: Dog) => Animal) => void
>cb : (x: Dog) => Animal
>Foo.f2 : (x: Dog) => Animal
>Foo : typeof Foo
>f2 : (x: Dog) => Animal
f1 = f2;
>f1 = f2 : (cb: (x: Dog) => Animal) => void
>f1 : (cb: (x: Animal) => Animal) => void
>f2 : (cb: (x: Dog) => Animal) => void
f2 = f1; // Error
>f2 = f1 : (cb: (x: Animal) => Animal) => void
>f2 : (cb: (x: Dog) => Animal) => void
>f1 : (cb: (x: Animal) => Animal) => void
}
namespace n2 {
>n2 : typeof n2
type BivariantHack<Input, Output> = { foo(x: Input): Output }["foo"];
>BivariantHack : (x: Input) => Output
>foo : (x: Input) => Output
>x : Input
declare let f1: (cb: BivariantHack<Animal, Animal>) => void;
>f1 : (cb: (x: Animal) => Animal) => void
>cb : (x: Animal) => Animal
declare let f2: (cb: BivariantHack<Dog, Animal>) => void;
>f2 : (cb: (x: Dog) => Animal) => void
>cb : (x: Dog) => Animal
f1 = f2;
>f1 = f2 : (cb: (x: Dog) => Animal) => void
>f1 : (cb: (x: Animal) => Animal) => void
>f2 : (cb: (x: Dog) => Animal) => void
f2 = f1; // Error
>f2 = f1 : (cb: (x: Animal) => Animal) => void
>f2 : (cb: (x: Dog) => Animal) => void
>f1 : (cb: (x: Animal) => Animal) => void
}
|