Skip to content

strictFunctionTypes option should strictly check callback parameters of override methods #19007

Closed
@falsandtru

Description

@falsandtru

As @aluanhaddad mentioned at #19004 (comment).

cc @ahejlsberg

TypeScript Version: master

Code

class C {
  a(f: (a: C) => C): void {
  }
}
class D extends C {
  p: boolean = true;
  a(f: (a: D) => D): void { // should throw an error here.
    console.log(this.p);
    this.p = f(new D()).p; // type is boolean, but value is undefined.
    console.log(this.p);
  }
}

const c: C = new D();
c.a(() => new C());

Expected behavior:

error

Actual behavior:

$ node built/local/tsc.js index.ts --strictFunctionTypes && node index.js
true
undefined

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions