type Fn = (val?: number) => number | Fn;
const add = (val: number = 0): number | Fn => {
let sum = 0;
const curried = (b: number) => {
sum = sum + b
return curried;
};
curried.valueOf = () => sum;
curried.toString = () => sum;
return curried(val) as number | Fn;
};
console.log(add()) // => 0
console.log(add(1)(2)(3)) // => 6
function add(val: number): StepFn | number
This expression is not callable.
Not all constituents of type 'number | StepFn' are callable.
Type 'number' has no call signatures.

This expression is not callable.
Not all constituents of type 'number | StepFn' are callable.
Type 'number' has no call signatures.