Here is the code snippet I am currently working on:
class X {
constructor(
private _x: number,
) {}
method1() {}
method2() {}
}
class Y {
constructor(
private _y: number,
) {}
method1() {}
method2() {}
}
class Z {
constructor(
private _z: number,
) {}
method1() {}
method2() {}
}
let itemList = [new X(1), new Y(2), new Z(3)];
itemList.forEach((item: any) => {
item.method1();
})
I have these three classes (X, Y, and Z) each with different constructors and methods that share the same name.
How can I specify a specific type other than any
in TypeScript to ensure that method1 is recognized by the compiler?