2014-08-15 23:33:16 +02:00
|
|
|
=== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality4.ts ===
|
|
|
|
// Base has required property, derived adds an optional property, no errors
|
|
|
|
|
|
|
|
interface Base { foo: string; }
|
|
|
|
>Base : Base
|
|
|
|
>foo : string
|
|
|
|
|
|
|
|
interface Derived extends Base { bar: string; }
|
|
|
|
>Derived : Derived
|
|
|
|
>Base : Base
|
|
|
|
>bar : string
|
|
|
|
|
|
|
|
interface T {
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
Foo: Base;
|
|
|
|
>Foo : Base
|
|
|
|
>Base : Base
|
|
|
|
}
|
|
|
|
|
|
|
|
interface S extends T {
|
|
|
|
>S : S
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
Foo2?: Derived // ok
|
|
|
|
>Foo2 : Derived
|
|
|
|
>Derived : Derived
|
|
|
|
}
|
|
|
|
|
|
|
|
interface T2 {
|
|
|
|
>T2 : T2
|
|
|
|
|
|
|
|
1: Base;
|
|
|
|
>Base : Base
|
|
|
|
}
|
|
|
|
|
|
|
|
interface S2 extends T2 {
|
|
|
|
>S2 : S2
|
|
|
|
>T2 : T2
|
|
|
|
|
|
|
|
2?: Derived; // ok
|
|
|
|
>Derived : Derived
|
|
|
|
}
|
|
|
|
|
|
|
|
interface T3 {
|
|
|
|
>T3 : T3
|
|
|
|
|
|
|
|
'1': Base;
|
|
|
|
>Base : Base
|
|
|
|
}
|
|
|
|
|
|
|
|
interface S3 extends T3 {
|
|
|
|
>S3 : S3
|
|
|
|
>T3 : T3
|
|
|
|
|
|
|
|
'1.0'?: Derived; // ok
|
|
|
|
>Derived : Derived
|
|
|
|
}
|
|
|
|
|
|
|
|
// object literal case
|
|
|
|
var a: { Foo: Base; }
|
|
|
|
>a : { Foo: Base; }
|
|
|
|
>Foo : Base
|
|
|
|
>Base : Base
|
|
|
|
|
|
|
|
var b: { Foo2?: Derived; }
|
|
|
|
>b : { Foo2?: Derived; }
|
|
|
|
>Foo2 : Derived
|
|
|
|
>Derived : Derived
|
|
|
|
|
|
|
|
var r = true ? a : b; // ok
|
2014-10-20 01:44:32 +02:00
|
|
|
>r : { Foo: Base; } | { Foo2?: Derived; }
|
|
|
|
>true ? a : b : { Foo: Base; } | { Foo2?: Derived; }
|
2014-08-15 23:33:16 +02:00
|
|
|
>a : { Foo: Base; }
|
|
|
|
>b : { Foo2?: Derived; }
|
|
|
|
|