I’ve created an interface CanDo
that defines one property someProperty
. The interface is used to implement composition (classes implementing this interface should be used as parameter for doSomething()
).
interface CanDo {
someProperty;
}
function doSomething(arg: CanDo) {
callOtherFunction(arg.someProperty);
}
class Class1 implements CanDo {
someProperty;
}
class Class2 {
someProperty;
}
const object1 = new Class1();
const object2 = new Class2();
doSomething(object1); //should work
doSomething(object2); //shouldn't work
The problem right now is that I can call doSomething() on both objects (since both define someProperty
), but I only want it to be possible for objects of Class1.
How could I achieve this?