I'm trying to implement a set of chained function but somehow I get stuck here.
interface ISimpleCalculator {
plus(value: number): this;
minus(value: number): this;
divide(value: number): this;
multiply(value: number): this;
sum(): void
}
interface ISpecialCalculator extends ISimpleCalculator {
specialPlus(value: number): ISimpleCalculator;
specialMinus(value: number): ISimpleCalculator;
}
let testCalculator: ISpecialCalculator;
testCalculator
.plus(20)
.multiply(2)
.specialPlus(40)
.plus(20)
.minus(5)
.specialMinus(20) //<-- Error! Property 'specialMinus' does not exist on type 'ISimpleCalculator'.
.sum()
I want to archive type check of the function in the chain. In the above example, I want the functions specialPlus and specialMinus in ISpecialCalculator to be used once only and ISimpleCalculator can be used for multiple times. I'm pretty fresh to the typescript and I've been trying different approaches (Advanced type (Pick & Omit)) with no success so far. I want to know is there any other way to help in this case.
ISpecialCalculatorinterface contains of more than one function and each of them is allowed to be used once only.