==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3.ts (2 errors) ==== // checking subtype relations for function types as it relates to contextual signature instantiation // error cases module Errors { class Base { foo: string; } class Derived extends Base { bar: string; } class Derived2 extends Derived { baz: string; } class OtherDerived extends Base { bing: string; } module WithNonGenericSignaturesInBaseType { // base type with non-generic call signatures interface A { a2: new (x: number) => string[]; a7: new (x: (arg: Base) => Derived) => (r: Base) => Derived2; a8: new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived; a10: new (...x: Base[]) => Base; a11: new (x: { foo: string }, y: { foo: string; bar: string }) => Base; a12: new (x: Array, y: Array) => Array; a14: { new (x: number): number[]; new (x: string): string[]; }; a15: new (x: { a: string; b: number }) => number; a16: { // type of parameter is overload set which means we can't do inference based on this type new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: boolean): boolean; new (a?: boolean): boolean; }): boolean[]; }; } interface I extends A { a2: new (x: T) => U[]; // error, contextual signature instantiation doesn't relate return types so U is {}, not a subtype of string[] } interface I2 extends A { ~~ !!! Interface 'I2' incorrectly extends interface 'A': !!! Types of property 'a2' are incompatible: !!! Type 'new (x: T) => U[]' is not assignable to type 'new (x: number) => string[]': !!! Types of parameters 'x' and 'x' are incompatible: !!! Type 'T' is not assignable to type 'number'. a2: new (x: T) => U[]; // error, no contextual signature instantiation since I2.a2 is not generic } interface I3 extends A { // valid, no inferences for V so it defaults to Derived2 a7: new (x: (arg: T) => U) => (r: T) => V; } interface I4 extends A { ~~ !!! Interface 'I4' incorrectly extends interface 'A': !!! Types of property 'a8' are incompatible: !!! Type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived': !!! Types of parameters 'y' and 'y' are incompatible: !!! Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived': !!! Types of parameters 'arg2' and 'arg2' are incompatible: !!! Type '{ foo: number; }' is not assignable to type 'Base': !!! Types of property 'foo' are incompatible: !!! Type 'number' is not assignable to type 'string'. a8: new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U; // error, type mismatch } interface I4B extends A { a10: new (...x: T[]) => T; // valid, parameter covariance works even after contextual signature instantiation } interface I4C extends A { a11: new (x: T, y: T) => T; // valid, even though x is a Base, parameter covariance works even after contextual signature instantiation } interface I4E extends A { a12: new >(x: Array, y: Array) => T; // valid, no inferences for T, defaults to Array } interface I6 extends A { a15: new (x: { a: T; b: T }) => T; // error, T is {} which isn't an acceptable return type } interface I7 extends A { a15: new (x: { a: T; b: T }) => number; // error, T defaults to Base, which is not compatible with number or string } interface I8 extends A { // ok, we relate each signature of a16 to b16, and within that, we make inferences from two different signatures in the respective A.a16 signature a16: new (x: new (a: T) => T) => T[]; } } module WithGenericSignaturesInBaseType { // base type has generic call signature interface B { a2: new (x: T) => T[]; } interface I6 extends B { a2: new (x: T) => string[]; // error } // base type has generic call signature interface C { a2: new (x: T) => string[]; } interface I7 extends C { a2: new (x: T) => T[]; // error } // base type has a generic call signature with overloads interface D { a14: { new (x: T): number[]; new (x: U): number[]; }; } interface I8 extends D { a14: new (x: T) => number[]; } } }