Closed
Description
As another point of #18963, strictFunctionTypes
prevents some method overriding. TypeScript should relax strictFunctionTypes
checks of method overriding. The current restriction is excessive on object-oriented programming.
cc @ahejlsberg
TypeScript Version: master
Code
declare class C {
a(f: (a: C) => C): void;
b(): (a: C) => C;
}
declare class D extends C {
p: void;
a(f: (a: D) => D): void;
b(): (a: D) => D;
}
Expected behavior:
no error
Actual behavior:
$ node built/local/tsc.js index.d.ts --noEmit --strictFunctionTypes
index.d.ts(5,15): error TS2415: Class 'D' incorrectly extends base class 'C'.
Types of property 'a' are incompatible.
Type '(f: (a: D) => D) => void' is not assignable to type '(f: (a: C) => C) => void'.
Types of parameters 'f' and 'f' are incompatible.
Types of parameters 'a' and 'a' are incompatible.
Type 'D' is not assignable to type 'C'.
Types of property 'b' are incompatible.
Type '() => (a: D) => D' is not assignable to type '() => (a: C) => C'.
Type '(a: D) => D' is not assignable to type '(a: C) => C'.
Types of parameters 'a' and 'a' are incompatible.
Type 'C' is not assignable to type 'D'.
Property 'p' is missing in type 'C'.
Metadata
Metadata
Assignees
Labels
No labels