48 lines
1.2 KiB
Text
48 lines
1.2 KiB
Text
=== tests/cases/compiler/contextualSignatureInstatiationContravariance.ts ===
|
|
interface Animal { x }
|
|
>Animal : Animal
|
|
>x : any
|
|
|
|
interface Giraffe extends Animal { y }
|
|
>Giraffe : Giraffe
|
|
>Animal : Animal
|
|
>y : any
|
|
|
|
interface Elephant extends Animal { y2 }
|
|
>Elephant : Elephant
|
|
>Animal : Animal
|
|
>y2 : any
|
|
|
|
var f2: <T extends Animal>(x: T, y: T) => void;
|
|
>f2 : <T extends Animal>(x: T, y: T) => void
|
|
>T : T
|
|
>Animal : Animal
|
|
>x : T
|
|
>T : T
|
|
>y : T
|
|
>T : T
|
|
|
|
var g2: (g: Giraffe, e: Elephant) => void;
|
|
>g2 : (g: Giraffe, e: Elephant) => void
|
|
>g : Giraffe
|
|
>Giraffe : Giraffe
|
|
>e : Elephant
|
|
>Elephant : Elephant
|
|
|
|
g2 = f2; // valid because both Giraffe and Elephant satisfy the constraint. T is Animal
|
|
>g2 = f2 : <T extends Animal>(x: T, y: T) => void
|
|
>g2 : (g: Giraffe, e: Elephant) => void
|
|
>f2 : <T extends Animal>(x: T, y: T) => void
|
|
|
|
var h2: (g1: Giraffe, g2: Giraffe) => void;
|
|
>h2 : (g1: Giraffe, g2: Giraffe) => void
|
|
>g1 : Giraffe
|
|
>Giraffe : Giraffe
|
|
>g2 : Giraffe
|
|
>Giraffe : Giraffe
|
|
|
|
h2 = f2; // valid because Giraffe satisfies the constraint. It is safe in the traditional contravariant fashion.
|
|
>h2 = f2 : <T extends Animal>(x: T, y: T) => void
|
|
>h2 : (g1: Giraffe, g2: Giraffe) => void
|
|
>f2 : <T extends Animal>(x: T, y: T) => void
|
|
|