Skip to content

strictFunctionTypes has different behavior with parameter types and return types #18963

Closed
@falsandtru

Description

@falsandtru

cc @ahejlsberg

TypeScript Version: master

Code

declare class C {
  static a(f: (a: C) => C): void;
  static b(): (a: C) => C;
}
declare class D extends C {
  private p: void;
  static a(f: (a: D) => D): void;
  static b(): (a: D) => D;
}

Expected behavior:

no error or both a and b make an error.

Actual behavior:

$ node built/local/tsc.js index.d.ts --noEmit --strictFunctionTypes
index.d.ts(5,15): error TS2417: Class static side 'typeof D' incorrectly extends base class static side 'typeof 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

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions