TypeScript/tests/baselines/reference/subtypingWithObjectMembersOptionality.types
2015-04-15 16:44:20 -07:00

165 lines
3 KiB
Plaintext

=== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality.ts ===
// Derived member is not optional but base member is, should be ok
interface Base { foo: string; }
>Base : Base
>foo : string
interface Derived extends Base { bar: string; }
>Derived : Derived
>Base : Base
>bar : string
interface Derived2 extends Derived { baz: string; }
>Derived2 : Derived2
>Derived : Derived
>baz : string
// S is a subtype of a type T, and T is a supertype of S, if one of the following is true, where S' denotes the apparent type (section 3.8.1) of S:
// - S' and T are object types and, for each member M in T, one of the following is true:
// - M is a property and S' contains a property N where
// M and N have the same name,
// the type of N is a subtype of that of M,
// M and N are both public or both private, and
// if M is a required property, N is also a required property.
// - M is an optional property and S' contains no property of the same name as M.
interface T {
>T : T
Foo?: Base;
>Foo : Base
>Base : Base
}
interface S extends T {
>S : S
>T : T
Foo: Derived
>Foo : Derived
>Derived : Derived
}
interface T2 {
>T2 : T2
1?: Base;
>Base : Base
}
interface S2 extends T2 {
>S2 : S2
>T2 : T2
1: Derived;
>Derived : Derived
}
interface T3 {
>T3 : T3
'1'?: Base;
>Base : Base
}
interface S3 extends T3 {
>S3 : S3
>T3 : T3
'1.': Derived;
>Derived : Derived
}
// object literal case
var a: { Foo?: Base; };
>a : { Foo?: Base; }
>Foo : Base
>Base : Base
var b = { Foo: <Derived>null };
>b : { Foo: Derived; }
>{ Foo: <Derived>null } : { Foo: Derived; }
>Foo : Derived
><Derived>null : Derived
>Derived : Derived
>null : null
var r = true ? a : b;
>r : { Foo?: Base; }
>true ? a : b : { Foo?: Base; }
>true : boolean
>a : { Foo?: Base; }
>b : { Foo: Derived; }
module TwoLevels {
>TwoLevels : typeof TwoLevels
interface T {
>T : T
Foo?: Base;
>Foo : Base
>Base : Base
}
interface S extends T {
>S : S
>T : T
Foo: Derived2
>Foo : Derived2
>Derived2 : Derived2
}
interface T2 {
>T2 : T2
1?: Base;
>Base : Base
}
interface S2 extends T2 {
>S2 : S2
>T2 : T2
1: Derived2;
>Derived2 : Derived2
}
interface T3 {
>T3 : T3
'1'?: Base;
>Base : Base
}
interface S3 extends T3 {
>S3 : S3
>T3 : T3
'1.': Derived2;
>Derived2 : Derived2
}
// object literal case
var a: { Foo?: Base; };
>a : { Foo?: Base; }
>Foo : Base
>Base : Base
var b = { Foo: <Derived2>null };
>b : { Foo: Derived2; }
>{ Foo: <Derived2>null } : { Foo: Derived2; }
>Foo : Derived2
><Derived2>null : Derived2
>Derived2 : Derived2
>null : null
var r = true ? a : b;
>r : { Foo?: Base; }
>true ? a : b : { Foo?: Base; }
>true : boolean
>a : { Foo?: Base; }
>b : { Foo: Derived2; }
}