Let's explore a simple example of typescript mixins:
import { Observable, of } from 'rxjs';
class Service<TDataType> {
public foo(f: TDataType): Observable<TDataType> { return of(f); }
}
type GConstructor<T = {}> = new (...args: any[]) => T;
type ServiceConstructible<TDataType> = GConstructor<Service<TDataType>>;
function applyBarMixin<TDataType, TBase extends ServiceConstructible<TDataType>>(Base: TBase) {
return class BarService extends Base{
public bar(b: TDataType): Observable<TDataType> {
return of(b);
}
};
}
After applying this mixin, the argument and return type of b()
become unknown:
const FooBar = applyBarMixin(Service<number>);
const service = new FooBar();
let x = service.bar(1);
// x: unknown
Even the argument of bar
becomes unknown! What could be the issue here?