TypeScript/tests/baselines/reference/subtypingWithObjectMembersOptionality4.types

78 lines
1.2 KiB
Plaintext
Raw Normal View History

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
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 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
Foo2?: Derived // ok
>Foo2 : 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
2?: Derived; // ok
>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.0'?: Derived; // ok
>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: { Foo2?: Derived; }
>b : { Foo2?: Derived; }
>Foo2 : Derived
>Derived : Derived
2014-08-15 23:33:16 +02:00
var r = true ? a : b; // ok
>r : { Foo: Base; } | { Foo2?: Derived; }
2014-10-20 01:44:32 +02:00
>true ? a : b : { Foo: Base; } | { Foo2?: Derived; }
2015-04-13 21:36:11 +02:00
>true : boolean
>a : { Foo: Base; }
>b : { Foo2?: Derived; }
2014-08-15 23:33:16 +02:00