Is there a way to create a CoR (Chain of Responsibility) that "knows"/"infers" when when called ("handle") results in promise?
For example, I want to create a simple chain with handlers.
input for each handler is number and output is string.
Handler can be sync or async (return Promise<string>) .
I want to use the chain like:
const syncHandlerInstance = new HandlerA()
const asyncHandlerInstance = new HandlerB()
const chain = syncHandlerInstance.setNext(asyncHandlerInstance)
const res = chain.handle(5)
I want typescript to know/infer that "res" is Promise<string> (as SOME (at least one) of the handlers in the chain is async)