TypeScript/tests/baselines/reference/covariance1.types

48 lines
649 B
Plaintext
Raw Normal View History

2014-08-15 23:33:16 +02:00
=== tests/cases/compiler/covariance1.ts ===
module M {
>M : typeof M
2014-08-15 23:33:16 +02:00
interface X { m1:number; }
>X : X
>m1 : number
2014-08-15 23:33:16 +02:00
export class XX implements X { constructor(public m1:number) { } }
>XX : XX
>X : X
>m1 : number
2014-08-15 23:33:16 +02:00
interface Y { x:X; }
>Y : Y
>x : X
>X : X
2014-08-15 23:33:16 +02:00
export function f(y:Y) { }
>f : (y: Y) => void
>y : Y
>Y : Y
2014-08-15 23:33:16 +02:00
var a:X;
>a : X
>X : X
2014-08-15 23:33:16 +02:00
f({x:a}); // ok
>f({x:a}) : void
>f : (y: Y) => void
2014-08-15 23:33:16 +02:00
>{x:a} : { x: X; }
>x : X
>a : X
2014-08-15 23:33:16 +02:00
var b:XX;
>b : XX
>XX : XX
2014-08-15 23:33:16 +02:00
f({x:b}); // ok covariant subtype
>f({x:b}) : void
>f : (y: Y) => void
2014-08-15 23:33:16 +02:00
>{x:b} : { x: XX; }
>x : XX
>b : XX
2014-08-15 23:33:16 +02:00
}