How do I write the following JavaScript in Typescript most efficiently?
-
sample.jsdoes a fairly simplified example for a code with the logic: "if callback, then callback, else promise" inaddand alogAndAddmethod reuses add, so the result oflogAndAddwill also be either a callback or a promise, depending on the input. -
test.jsmakes sure that this is supposed to work -
sample.d.tsis how I assume the.d.tsshould look like -
sample.tsis not working but shows how I thought TypeScript could work neatly.
How would you write it in TypeScript?
This is what I have come up with: