==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembersOptionality2.ts (9 errors) ==== // M is optional and S contains no property with the same name as M // N is optional and T contains no property with the same name as N 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 { other: Base; } interface E { other: Derived; } interface F { other?: 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 { other?: Base; } interface E { other?: Derived; } interface F { other: Derived; } var d: D; var e: E; var f: F; c = d; // error ~ !!! Type 'D' is not assignable to type 'C': !!! Property 'opt' is missing in type 'D'. c = e; // error ~ !!! Type 'E' is not assignable to type 'C': !!! Property 'opt' is missing in type 'E'. c = f; // error ~ !!! Type 'F' is not assignable to type 'C': !!! Property 'opt' is missing in type 'F'. c = a; // ok a = d; // error ~ !!! Type 'D' is not assignable to type '{ opt: Base; }': !!! Property 'opt' is missing in type 'D'. a = e; // error ~ !!! Type 'E' is not assignable to type '{ opt: Base; }': !!! Property 'opt' is missing in type 'E'. a = f; // error ~ !!! Type 'F' is not assignable to type '{ opt: Base; }': !!! Property 'opt' is missing in type 'F'. a = c; // ok b = d; // error ~ !!! Type 'D' is not assignable to type '{ opt: Base; }': !!! Property 'opt' is missing in type 'D'. b = e; // error ~ !!! Type 'E' is not assignable to type '{ opt: Base; }': !!! Property 'opt' is missing in type 'E'. b = f; // error ~ !!! Type 'F' is not assignable to type '{ opt: Base; }': !!! Property 'opt' is missing in type 'F'. b = a; // ok b = c; // ok }