Skip to content

Instantly share code, notes, and snippets.

@palpich
Created February 17, 2021 14:37
Show Gist options
  • Save palpich/80d696d0bae7d3e67fd77b5a7cf4594c to your computer and use it in GitHub Desktop.
Save palpich/80d696d0bae7d3e67fd77b5a7cf4594c to your computer and use it in GitHub Desktop.
sdfsdf
function add(val: number): typeof add;
function add(): number;
function add(val?: number): number | typeof add {
if (val === undefined) return 0;
let sum = val;
function nextFn(val1: number): typeof nextFn;
function nextFn(): number;
function nextFn(val1?: number): number | typeof nextFn {
if (val1 === undefined) return sum;
sum += val1;
return nextFn;
}
return nextFn;
}
console.log(add());
console.log(add(1)(2)());
const bar = add(1)()
const foo = add(1)(2)(2)();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment