Say that I have declared my classes and types as below
declare type Class<T = any> = new (...args: any[]) => T
export class BaseIntersectHandler<UuidException extends Class<Error>>
{
constructor(private uuid_exception: UuidException) {
// implementation
}
debugMethod(): void {
throw new this.uuid_exception("debug string")
}
}
export class ClickHandlerUuidException extends Error
{
// implementation
}
export class ClickHandler extends BaseIntersectHandler<ClickHandlerUuidException>
{
constructor() {
super(ClickHandlerUuidException)
}
}
const sampleInstance = new ClickHander()
sampleInstance.debugMethod() // should throw the error from base method
Implementing above gives the error below when compiling:
TS2344: Type 'ClickHandlerUuidException' does not satisfy the constraint 'Class<Error>'.
Type 'ClickHandlerUuidException' provides no match for the signature 'new (...args: any[]): Error'.
I'm trying to be specific about UuidException generic being inherited from Error in JS. How should I change this? I'm sure this is a duplicate, but any help is appreciated!