I encountered an issue in my code: The error message 'Property 'debug' does not exist on type 'HardToDebugUser'.' was displayed. It seems like Typescript failed to infer the mixin class correctly. Can you please explain this to me? Thank you!
type ClassConstructor<T> = new(...args: any[]) => T
function withEzDebug<C extends ClassConstructor<{
getDebugValue(): object
}>>(Class: C) : C{
type Hi = typeof Class;
return class extends Class {
constructor(...args: any[]) {
super(...args)
}
debug() {
let Name = Class.constructor.name
let value = this.getDebugValue()
return Name + '(' + JSON.stringify(value) + ')'
}
}
}
class HardToDebugUser {
constructor(private name: string, private grade: number) {
this.name = name;
this.grade = grade;
}
getDebugValue() {
return {
name: this.name,
grade: this.grade
}
}
}
let User = withEzDebug(HardToDebugUser);
let userWithDebug = new User("hi", 1);
userWithDebug.debug();
Can you provide guidance on how to correctly infer a mixin class in Typescript.