In Angular, it appears as though many operations can receive a straight value or an observable for that value. I want to implement a function that does the same. Are there any pitfalls to just implementing a check and casting: if(typeof input.subscribe != 'function') input = of(input)
?
It appears as though a popular approach to 'overloading' is to add an options object whereby a user can specify a type of the input. Another approach I have seen is to just accept an object with optional parameters:
function x(input){
if (input.observable) input = input.observable;
if (input.raw) input = input.raw
}
Of course, I could just break it up into a normal function and an async function or require the caller to supply an observable. However, I like my approach - I just want to know if there are any pitfalls I'm not seeing.