My WebStorm keeps showing the error message below repeatedly, despite my script compiling and running without any issues. Any ideas on why this is happening?
Error:(6, 9) TS2322:Type 'AnotherRandomClass' is not assignable to type 'A'.
AnotherRandomClass.ts
import * as Events from "events";
export default class AnotherRandomClass extends Events.EventEmitter {
static instance: AnotherRandomClass;
constructor() {
super();
AnotherRandomClass.instance = this;
}
public static getInstance(): AnotherRandomClass {
return AnotherRandomClass.instance;
}
}
RandomListener.ts
import * as Events from "events";
import AnotherRandomClass from "./AnotherRandomClass";
export default class RandomListener {
public getBaseClass<A extends Events.EventEmitter>(): A {
return AnotherRandomClass.getInstance();
}
}
tests.ts
import AnotherRandomClass from "./AnotherRandomClass"
import RandomListener from "./RandomListener";
import * as Events from "events";
new AnotherRandomClass();
console.log(AnotherRandomClass.getInstance() instanceof Events.EventEmitter);
console.log(new RandomListener().getBaseClass());
result of tests
λ node tests.js
true
AnotherRandomClass {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined }