mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
22 lines
1.3 KiB
Plaintext
22 lines
1.3 KiB
Plaintext
contextualSignatureInstatiationContravariance.ts(8,1): error TS2322: Type '<T extends Animal>(x: T, y: T) => void' is not assignable to type '(g: Giraffe, e: Elephant) => void'.
|
|
Types of parameters 'y' and 'e' are incompatible.
|
|
Property 'y' is missing in type 'Elephant' but required in type 'Giraffe'.
|
|
|
|
|
|
==== contextualSignatureInstatiationContravariance.ts (1 errors) ====
|
|
interface Animal { x }
|
|
interface Giraffe extends Animal { y }
|
|
interface Elephant extends Animal { y2 }
|
|
|
|
declare var f2: <T extends Animal>(x: T, y: T) => void;
|
|
|
|
declare var g2: (g: Giraffe, e: Elephant) => void;
|
|
g2 = f2; // error because Giraffe and Elephant are disjoint types
|
|
~~
|
|
!!! error TS2322: Type '<T extends Animal>(x: T, y: T) => void' is not assignable to type '(g: Giraffe, e: Elephant) => void'.
|
|
!!! error TS2322: Types of parameters 'y' and 'e' are incompatible.
|
|
!!! error TS2322: Property 'y' is missing in type 'Elephant' but required in type 'Giraffe'.
|
|
!!! related TS2728 contextualSignatureInstatiationContravariance.ts:2:36: 'y' is declared here.
|
|
|
|
declare var h2: (g1: Giraffe, g2: Giraffe) => void;
|
|
h2 = f2; // valid because Giraffe satisfies the constraint. It is safe in the traditional contravariant fashion. |