How do I write the following JavaScript in Typescript most efficiently?
-
sample.js
does a fairly simplified example for a code with the logic: "if callback, then callback, else promise" inadd
and alogAndAdd
method reuses add, so the result oflogAndAdd
will also be either a callback or a promise, depending on the input. -
test.js
makes sure that this is supposed to work -
sample.d.ts
is how I assume the.d.ts
should look like -
sample.ts
is 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: