TypeScript/tests/baselines/reference/assignmentCompatWithObjectMembersOptionality.errors.txt
2014-07-12 17:30:19 -07:00

107 lines
2.7 KiB
Plaintext

==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembersOptionality.ts (6 errors) ====
// Derived member is not optional but base member is, should be ok
class Base { foo: string; }
class Derived extends Base { bar: string; }
class Derived2 extends Derived { baz: string; }
module TargetHasOptional {
// targets
interface C {
opt?: Base
}
var c: C;
var a: { opt?: Base; }
var b: typeof a = { opt: new Base() }
// sources
interface D {
opt: Base;
}
interface E {
opt: Derived;
}
interface F {
opt?: Derived;
}
var d: D;
var e: E;
var f: F;
// all ok
c = d;
c = e;
c = f;
c = a;
a = d;
a = e;
a = f;
a = c;
b = d;
b = e;
b = f;
b = a;
b = c;
}
module SourceHasOptional {
// targets
interface C {
opt: Base
}
var c: C;
var a: { opt: Base; }
var b = { opt: new Base() }
// sources
interface D {
opt?: Base;
}
interface E {
opt?: Derived;
}
interface F {
opt: Derived;
}
var d: D;
var e: E;
var f: F;
c = d; // error
~
!!! Type 'D' is not assignable to type 'C':
!!! Required property 'opt' cannot be reimplemented with optional property in 'D'.
c = e; // error
~
!!! Type 'E' is not assignable to type 'C':
!!! Required property 'opt' cannot be reimplemented with optional property in 'E'.
c = f; // ok
c = a; // ok
a = d; // error
~
!!! Type 'D' is not assignable to type '{ opt: Base; }':
!!! Required property 'opt' cannot be reimplemented with optional property in 'D'.
a = e; // error
~
!!! Type 'E' is not assignable to type '{ opt: Base; }':
!!! Required property 'opt' cannot be reimplemented with optional property in 'E'.
a = f; // ok
a = c; // ok
b = d; // error
~
!!! Type 'D' is not assignable to type '{ opt: Base; }':
!!! Required property 'opt' cannot be reimplemented with optional property in 'D'.
b = e; // error
~
!!! Type 'E' is not assignable to type '{ opt: Base; }':
!!! Required property 'opt' cannot be reimplemented with optional property in 'E'.
b = f; // ok
b = a; // ok
b = c; // ok
}