tests/cases/compiler/inferFromGenericFunctionReturnTypes1.ts(34,5): error TS2684: The 'this' context of type 'SetOf<A>' is not assignable to method's 'this' of type 'SetOf<A>'.
  Type 'A' is not assignable to type 'A'. Two different types with this name exist, but they are unrelated.
    'A' could be instantiated with an arbitrary type which could be unrelated to 'A'.
tests/cases/compiler/inferFromGenericFunctionReturnTypes1.ts(34,20): error TS2684: The 'this' context of type 'SetOf<B>' is not assignable to method's 'this' of type 'SetOf<A>'.
tests/cases/compiler/inferFromGenericFunctionReturnTypes1.ts(42,5): error TS2684: The 'this' context of type 'SetOf<A>' is not assignable to method's 'this' of type 'SetOf<A>'.
tests/cases/compiler/inferFromGenericFunctionReturnTypes1.ts(43,25): error TS2684: The 'this' context of type 'SetOf<A>' is not assignable to method's 'this' of type 'SetOf<A>'.
tests/cases/compiler/inferFromGenericFunctionReturnTypes1.ts(50,1): error TS2684: The 'this' context of type 'SetOf<number>' is not assignable to method's 'this' of type 'SetOf<A>'.
  Type 'number' is not assignable to type 'A'.
    'A' could be instantiated with an arbitrary type which could be unrelated to 'number'.
tests/cases/compiler/inferFromGenericFunctionReturnTypes1.ts(51,1): error TS2684: The 'this' context of type 'SetOf<number>' is not assignable to method's 'this' of type 'SetOf<A>'.
tests/cases/compiler/inferFromGenericFunctionReturnTypes1.ts(52,1): error TS2684: The 'this' context of type 'SetOf<number>' is not assignable to method's 'this' of type 'SetOf<A>'.
tests/cases/compiler/inferFromGenericFunctionReturnTypes1.ts(54,1): error TS2684: The 'this' context of type 'SetOf<number>' is not assignable to method's 'this' of type 'SetOf<A>'.
tests/cases/compiler/inferFromGenericFunctionReturnTypes1.ts(63,1): error TS2684: The 'this' context of type 'SetOf<number>' is not assignable to method's 'this' of type 'SetOf<A>'.
tests/cases/compiler/inferFromGenericFunctionReturnTypes1.ts(68,16): error TS2339: Property 'toUpperCase' does not exist on type 'number'.


==== tests/cases/compiler/inferFromGenericFunctionReturnTypes1.ts (10 errors) ====
    // Repro from #15680
    
    // This is a contrived class. We could do the same thing with Observables, etc.
    class SetOf<A> {
      _store: A[];
    
      add(a: A) {
        this._store.push(a);
      }
    
      transform<B>(transformer: (a: SetOf<A>) => SetOf<B>): SetOf<B> {
        return transformer(this);
      }
    
      forEach(fn: (a: A, index: number) => void) {
          this._store.forEach((a, i) => fn(a, i));
      }
    }
    
    function compose<A, B, C, D, E>(
      fnA: (a: SetOf<A>) => SetOf<B>, 
      fnB: (b: SetOf<B>) => SetOf<C>, 
      fnC: (c: SetOf<C>) => SetOf<D>,
      fnD: (c: SetOf<D>) => SetOf<E>,
    ):(x: SetOf<A>) => SetOf<E>;
    /* ... etc ... */
    function compose<T>(...fns: ((x: T) => T)[]): (x: T) => T {
      return (x: T) => fns.reduce((prev, fn) => fn(prev), x);
    }
    
    function map<A, B>(fn: (a: A) => B): (s: SetOf<A>) => SetOf<B> {
      return (a: SetOf<A>) => {
        const b: SetOf<B> = new SetOf();
        a.forEach(x => b.add(fn(x)));
        ~
!!! error TS2684: The 'this' context of type 'SetOf<A>' is not assignable to method's 'this' of type 'SetOf<A>'.
!!! error TS2684:   Type 'A' is not assignable to type 'A'. Two different types with this name exist, but they are unrelated.
!!! error TS2684:     'A' could be instantiated with an arbitrary type which could be unrelated to 'A'.
                       ~
!!! error TS2684: The 'this' context of type 'SetOf<B>' is not assignable to method's 'this' of type 'SetOf<A>'.
        return b;
      }
    }
    
    function filter<A>(predicate: (a: A) => boolean): (s: SetOf<A>) => SetOf<A> {
      return (a: SetOf<A>) => {
        const result = new SetOf<A>();
        a.forEach(x => {
        ~
!!! error TS2684: The 'this' context of type 'SetOf<A>' is not assignable to method's 'this' of type 'SetOf<A>'.
          if (predicate(x)) result.add(x);
                            ~~~~~~
!!! error TS2684: The 'this' context of type 'SetOf<A>' is not assignable to method's 'this' of type 'SetOf<A>'.
        });
       return result;
      }
    }
    
    const testSet = new SetOf<number>();
    testSet.add(1);
    ~~~~~~~
!!! error TS2684: The 'this' context of type 'SetOf<number>' is not assignable to method's 'this' of type 'SetOf<A>'.
!!! error TS2684:   Type 'number' is not assignable to type 'A'.
!!! error TS2684:     'A' could be instantiated with an arbitrary type which could be unrelated to 'number'.
    testSet.add(2);
    ~~~~~~~
!!! error TS2684: The 'this' context of type 'SetOf<number>' is not assignable to method's 'this' of type 'SetOf<A>'.
    testSet.add(3);
    ~~~~~~~
!!! error TS2684: The 'this' context of type 'SetOf<number>' is not assignable to method's 'this' of type 'SetOf<A>'.
    
    testSet.transform(
    ~~~~~~~
!!! error TS2684: The 'this' context of type 'SetOf<number>' is not assignable to method's 'this' of type 'SetOf<A>'.
      compose(
        filter(x => x % 1 === 0),
        map(x => x + x),
        map(x => x + '!!!'),
        map(x => x.toUpperCase())
      )
    )
    
    testSet.transform(
    ~~~~~~~
!!! error TS2684: The 'this' context of type 'SetOf<number>' is not assignable to method's 'this' of type 'SetOf<A>'.
      compose(
        filter(x => x % 1 === 0),
        map(x => x + x),
        map(x => 123),  // Whoops a bug
        map(x => x.toUpperCase()) // causes an error!
                   ~~~~~~~~~~~
!!! error TS2339: Property 'toUpperCase' does not exist on type 'number'.
      )
    )
    