TypeScript/tests/baselines/reference/subtypingWithObjectMembersOptionality.types

165 lines
3 KiB
Plaintext
Raw Normal View History

2014-08-15 23:33:16 +02:00
=== 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
2014-08-15 23:33:16 +02:00
interface Derived extends Base { bar: string; }
>Derived : Derived
>Base : Base
>bar : string
2014-08-15 23:33:16 +02:00
interface Derived2 extends Derived { baz: string; }
>Derived2 : Derived2
>Derived : Derived
>baz : string
2014-08-15 23:33:16 +02:00
// 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
2014-08-15 23:33:16 +02:00
Foo?: Base;
>Foo : Base
>Base : Base
2014-08-15 23:33:16 +02:00
}
interface S extends T {
>S : S
>T : T
2014-08-15 23:33:16 +02:00
Foo: Derived
>Foo : Derived
>Derived : Derived
2014-08-15 23:33:16 +02:00
}
interface T2 {
>T2 : T2
2014-08-15 23:33:16 +02:00
1?: Base;
>Base : Base
2014-08-15 23:33:16 +02:00
}
interface S2 extends T2 {
>S2 : S2
>T2 : T2
2014-08-15 23:33:16 +02:00
1: Derived;
>Derived : Derived
2014-08-15 23:33:16 +02:00
}
interface T3 {
>T3 : T3
2014-08-15 23:33:16 +02:00
'1'?: Base;
>Base : Base
2014-08-15 23:33:16 +02:00
}
interface S3 extends T3 {
>S3 : S3
>T3 : T3
2014-08-15 23:33:16 +02:00
'1.': Derived;
>Derived : Derived
2014-08-15 23:33:16 +02:00
}
// object literal case
var a: { Foo?: Base; };
>a : { Foo?: Base; }
>Foo : Base
>Base : Base
2014-08-15 23:33:16 +02:00
var b = { Foo: <Derived>null };
>b : { Foo: Derived; }
2014-08-15 23:33:16 +02:00
>{ Foo: <Derived>null } : { Foo: Derived; }
>Foo : Derived
2014-08-15 23:33:16 +02:00
><Derived>null : Derived
>Derived : Derived
2015-04-13 21:36:11 +02:00
>null : null
2014-08-15 23:33:16 +02:00
var r = true ? a : b;
>r : { Foo?: Base; }
2014-08-15 23:33:16 +02:00
>true ? a : b : { Foo?: Base; }
2015-04-13 21:36:11 +02:00
>true : boolean
>a : { Foo?: Base; }
>b : { Foo: Derived; }
2014-08-15 23:33:16 +02:00
module TwoLevels {
>TwoLevels : typeof TwoLevels
2014-08-15 23:33:16 +02:00
interface T {
>T : T
2014-08-15 23:33:16 +02:00
Foo?: Base;
>Foo : Base
>Base : Base
2014-08-15 23:33:16 +02:00
}
interface S extends T {
>S : S
>T : T
2014-08-15 23:33:16 +02:00
Foo: Derived2
>Foo : Derived2
>Derived2 : Derived2
2014-08-15 23:33:16 +02:00
}
interface T2 {
>T2 : T2
2014-08-15 23:33:16 +02:00
1?: Base;
>Base : Base
2014-08-15 23:33:16 +02:00
}
interface S2 extends T2 {
>S2 : S2
>T2 : T2
2014-08-15 23:33:16 +02:00
1: Derived2;
>Derived2 : Derived2
2014-08-15 23:33:16 +02:00
}
interface T3 {
>T3 : T3
2014-08-15 23:33:16 +02:00
'1'?: Base;
>Base : Base
2014-08-15 23:33:16 +02:00
}
interface S3 extends T3 {
>S3 : S3
>T3 : T3
2014-08-15 23:33:16 +02:00
'1.': Derived2;
>Derived2 : Derived2
2014-08-15 23:33:16 +02:00
}
// object literal case
var a: { Foo?: Base; };
>a : { Foo?: Base; }
>Foo : Base
>Base : Base
2014-08-15 23:33:16 +02:00
var b = { Foo: <Derived2>null };
>b : { Foo: Derived2; }
2014-08-15 23:33:16 +02:00
>{ Foo: <Derived2>null } : { Foo: Derived2; }
>Foo : Derived2
2014-08-15 23:33:16 +02:00
><Derived2>null : Derived2
>Derived2 : Derived2
2015-04-13 21:36:11 +02:00
>null : null
2014-08-15 23:33:16 +02:00
var r = true ? a : b;
>r : { Foo?: Base; }
2014-08-15 23:33:16 +02:00
>true ? a : b : { Foo?: Base; }
2015-04-13 21:36:11 +02:00
>true : boolean
>a : { Foo?: Base; }
>b : { Foo: Derived2; }
2014-08-15 23:33:16 +02:00
}