Repository: TypeScript
Issue: Property inherited from mixin of function type with parameter of type "this" incorrectly extends base class static side
Labels: Bug,Help Wanted

# Bug Report

### 🔎 Search Terms
mixin, this type, function parameter 

### 🕗 Version & Regression Information

<!-- When did you start seeing this bug occur?

"Bugs" that have existed in TS for a long time are very likely to be FAQs; refer to
  https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs

If possible, please try testing the nightly version of TS to see if it's already been fixed.
For npm: `typescript@next`
This is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly

Note: The TypeScript Playground can be used to try older versions of TypeScript.

Please keep and fill in the line that best applies:
-->

- This changed between versions 4.8.4 and 4.9.5

### ⏯ Playground Link

<!--
  A link to a TypeScript Playground "Share" link which shows this behavior

  The TypeScript Workbench can be used for more complex setups, try
  https://www.typescriptlang.org/dev/bug-workbench/

  As a last resort, you can link to a repo, but these will be slower for us to investigate.
-->
[Playground link](https://www.typescriptlang.org/play?declaration=false&ts=4.9.5#code/CYUwxgNghgTiAEYD2A7AzgF3gFQJ4AcQAueAMQFcUwMBLVAYVUxnOqRgG4AoL0SWBDRQYQMAGZQwCPIQA82AHzwQADxEpgaMpWp0U8AN5d4J+ChAB3eAAoAdPdgBzNCSgpcAbQC6AShLZuAF8efjQtABFyAFso3ANgrjEdWlR4AFkaFXl6ZTUQDS0ZEFl4hQVrACEoNGIceh8jU3goACNmSSxQwpBMKprc9U14PoQjYybTVvbqeBFMCioSaxqIMRIMAAsaNB94AF4lADckGmBucYn4fBgkEWoQYGa2jBgO+ABlJCiQNJBNpGAyxAq3WWx2JGYQkc50uJluG1Ev3+gL88EhKEcjVhTTgGHIMH0m22tk+3yRGwB1iJO242ISTWCOL++P02B6GBGQRCTCwUUyD326Uy1kiMVwPnOAHpJaIbjB4AAqFC3BW5Qj3R4IuBcLo4dkDfJDPkqB5YkxzDALMCC6m2C0AVXwPCaFoACjd8BCXlDBQByC2+mGma63cAiR6kn5-CmAlZrWZg1HoxyGC4TXEstHAsR29nupD4WmmenBmA0Q5QESzdmOoEghPbVHHU6p7Fx3OYfOFtPBBLIdBYC1szCC8xWYcYawSrjS2XsNVhgVakBcIfsjuWnSCuvxjAEEBIMTwY0PXYHQyBIA)

### 💻 Code

<!-- Please post the relevant code sample here as well-->
```ts
declare const Type: FunctionConstructor;
declare interface Type<T> extends Function {
    new (...args: any[]): T;
}

class Dummy{}

function Mix<TC extends Type<{}>>(Base: TC){
    abstract class TestBase extends Base {

        abstract testFunc: (self: this) => void;

        protected abstract SomeMethod(self: this): string;

        otherMethod(): string{
            return this.SomeMethod(this);
        }

    }
    return TestBase;
}

const mixed = Mix(Dummy);

//error *not* expected here
class Test extends mixed{
    testFunc = this.testUp

    testProp: string = 'test';

    protected SomeMethod(self: this): string {
        return self.testProp;
    }

    private testUp(self: this): void {
        self.testProp;
    }
}

const testTest = new Test();
//error expected here
testTest.testFunc = (self: typeof mixed) => {}
```

### 🙁 Actual behavior

The code fails to compile with the error 

***
Class static side 'typeof Test' incorrectly extends base class static side '{ prototype: Mix<any>.TestBase; apply(this: Function, thisArg: any, argArray?: any): any; call(this: Function, thisArg: any, ...argArray: any[]): any; ... 6 more ...; [Symbol.hasInstance](value: any): boolean; } & typeof Dummy'.
  Types of property 'prototype' are incompatible.
    Type 'Test' is not assignable to type 'Mix<any>.TestBase & Dummy'.
      Type 'Test' is not assignable to type 'Mix<any>.TestBase'.
        Types of property 'testFunc' are incompatible.
          Type '(self: Test) => void' is not assignable to type '(self: Mix<any>.TestBase) => void'.
            Types of parameters 'self' and 'self' are incompatible.
              Type 'Mix<any>.TestBase' is missing the following properties from type 'Test': testProp, testUp
Type '(self: typeof mixed) => void' is not assignable to type '(self: Test) => void'.
  Types of parameters 'self' and 'self' are incompatible.
    Type 'Test' is not assignable to type '((abstract new (...args: any[]) => Mix<typeof Dummy>.TestBase) & { prototype: Mix<any>.TestBase; apply(this: Function, thisArg: any, argArray?: any): any; ... 7 more ...; [Symbol.hasInstance](value: any): boolean; }) & typeof Dummy'.
      Type 'Test' is missing the following properties from type '(abstract new (...args: any[]) => Mix<typeof Dummy>.TestBase) & { prototype: Mix<any>.TestBase; apply(this: Function, thisArg: any, argArray?: any): any; ... 7 more ...; [Symbol.hasInstance](value: any): boolean; }': prototype, apply, call, bind, and 5 more.
***

### 🙂 Expected behavior

Prior to 4.9.5 this error did not occur.  It seems to me that this is treating methods differently than function valued properties which is why I included "SomeMethod" in my example.  Both "SomeMethod" and "testFunc" contain a function which takes a parameter of type "this" yet one produces the error while the other does not.  Perhaps there is a good reason for this which I am missing but to my eye the two scenarios (method vs property) are very similar if not the same.

Swapping from 4.9.5 to 4.8.4 in the playground makes the error go away.

Here is a playground with a similar scenario without mixin:

[Playground link](https://www.typescriptlang.org/play?declaration=false&ts=4.9.5#code/IYIwzgLgTsDGEAJYBthjAgKgU0gITWwQQG8AoM44gBygHsJt5sATBUSGeBRyAMQCuAO1gAuBAAow2ZADNxEABYBLMAEoEAXgB8CAG51lLANwUqCWgyaM2HaHEQBlOgFtsAWWxK6LKTPk8KurinMpCAOamlFQMithQnt6+aiHQYeHk5uZQXgJQQoGqAHTObomKPhJKqmqm5gC+ZI1kKGgYOJAI2AAejEIs7bgQBNKkZlSWjMxsvBCCIlqFYEWzAKrU48SzAAr01KlQ6YsA5LPHUeaT1qwIpR5eFb7ScgpBKQihEWNZVDkQeQVnrIVkNdnRqHUqM1Loc9MBGDwhus-C8lu8DEZvj8Pv4QZAwRDosRms1YHQhJ1ZoshNgAO5YIYSWpAA)

My actual use case is for the function valued property to be protected.  I understand why the following causes an error

[Playground link](https://www.typescriptlang.org/play?declaration=false&ts=4.9.5#code/IYIwzgLgTsDGEAJYBthjAgKgU0gITWwQQG8AoM440SGeBCXCAMQFcA7WALgQAoxsyAGY8IACwCWYAJQIAvAD4EANwD2EgCYBuClQQAHKKsbxsGhDWhxEAZVUBbbAFls41Rv6CRDSTJ60JdgBzHUoqYzFsKBc3D2l-aECg8j09KFdWKHYfKQA6O0cYsXdecSlpHT0AXzIashQ0DBxIBGwAD0Z2DSamAgFSXSpGSDZOeRywXOGIAFV9QeJpgAUjfQSoJPGAcmmt0L1DY2xTcwLnV2KPAWFRX3iEAOCB1Kp0iEzs66EpphXVfUqVDqBw2ymAjAYTDmnhuE3uak0zxeDy8P0gfwBYWIdTqDXQWCYACZWh1sF0evhCOQsZCRhxYOMypNpnMFgYjCZGKcHOdYjDvEz7o8gkiXm8PggdnsacCqIYJGCISz9PzbuUeAjzClkTLahRYKp2C1puN2NgAO4EyC8Cr1Q3G3qEHjNCB9IhyWkQUIGo2IabEj1my0uwk2nQ+h2UgSE52O-oe-2hAD0SfEREOIGQ2HsCEi6QQUh84M9buJ5okyGQCHYxlzwGURDTCAARMtVs32f8ohAAJ4k-THLkIEB9vEYZsu5tkaZutEsemlOPYQm2oA)

but it seems to me that even that could be alleviated if the property is protected

[Playground link](https://www.typescriptlang.org/play?declaration=false&ts=4.9.5#code/IYIwzgLgTsDGEAJYBthjAgKgU0gITWwQQG8AoM44gBygHsJt5sATBUSGeBRyAMQCuAO1gAuBAAow2ZADNxEABYBLMAEoEAXgB8CAG51lLANwUqCWgyaM2HaHEQBlOgFtsAWWxK6LKTPk8KurinMpCAOamlFQMithQnt6+aiHQYeHk5uZQXgJQQoGqAHTObomKPhJKqmqm5gC+ZI1kKGgYOJAI2AAejEIs7bgQBNKkZlSWjMxsvBCCIlqFYEWzAKrU48SzAAr01KlQ6YsA5LPHUeaT1qwIpR5eFb7ScgpBKQihEWNZVDkQeQVnrIVkNdnRqHUqM1Loc9MBGDwhus-C8lu8DEZvj8Pv4QZAwRDosRms1WugsEMAExdXrYfqDfCEchEiz0KY2RH8YSwRbVZZrDYsq7TW6ue5JFEBPnvT7hLE-P4AhCnc4s6ETWHwogCyWvGriDFsTLYtVNCiwOhCTqzRZCbAAdwpkAktRalutQxG2HEHWGhF5QyiFqtiFm1M0CDtjt9lJdpmDHsZ0kpPs9-ojYaiAHos0I6I77URgDlIwx2MhkPmbhA6DwoABPJbsRDACtkWZevFzblVNPJ11AA)