diff --git a/src/compiler.ts b/src/compiler.ts index 3dfdcabd6e..6955383478 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -6610,8 +6610,8 @@ export class Compiler extends DiagnosticEmitter { let overrideInstance = overrideInstances[i]; if (!overrideInstance.is(CommonFlags.Compiled)) continue; // errored - const overrideSignature = overrideInstance.signature; - const originalSignature = instance.signature; + let overrideSignature = overrideInstance.signature; + let originalSignature = instance.signature; if (!overrideSignature.isAssignableTo(originalSignature, true)) { this.error( diff --git a/src/types.ts b/src/types.ts index fdaa22f278..30e6e42558 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1053,11 +1053,10 @@ export class Signature { let targetThisType = target.thisType; if (thisThisType != null && targetThisType != null){ - const compatibleThisType = checkCompatibleOverride ? thisThisType.canExtendOrImplement(targetThisType) + const compatibleThisType = checkCompatibleOverride + ? thisThisType.canExtendOrImplement(targetThisType) : targetThisType.isAssignableTo(thisThisType); - if (!compatibleThisType) { - return false; - } + if (!compatibleThisType) return false; }else if (thisThisType || targetThisType){ return false; } diff --git a/tests/compiler/class-member-function-as-parameter.ts b/tests/compiler/class-member-function-as-parameter.ts index ec5b591a64..611f0fbf03 100644 --- a/tests/compiler/class-member-function-as-parameter.ts +++ b/tests/compiler/class-member-function-as-parameter.ts @@ -1,14 +1,19 @@ class A { foo(): void { } } + class B extends A { foo(): void { } } + function foo(): void { } + function consumeA(callback: (this: A) => void): void { } function consumeB(callback: (this: B) => void): void { } + const a = new A(); const b = new B(); + consumeB(a.foo); // shouldn't error consumeA(foo); // should error consumeA(b.foo); // should error