-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(Notification): Define a private 'isObserver' type guard. #1211
Conversation
This is a bit tricky... technically any object is a valid Observers aren't required to have This is valid: observable.subscribe({ error(err) { console.log('I have an error'); }); What you've implemented is a test for We could also test for function isNotObserver(o: any): boolean {
return !o || (typeof o.next !== 'function' && typeof o.error !== 'function' && typeof o.completed !== 'function');
} |
Also, we're not using this functionality in more than one spot yet, I don't think. So we probably don't need to abstract it out just yet. If this were an end-user app, or any more than a one-liner, then absolutely I'd say we should abstract it into its own call. What do you think? |
Feels like the cast to I could see type guards for |
I agree these points:
I think we should change a type NextObserver<T> = {
next(value: T): void;
};
type ErrorObserver = {
error(error: any): void;
};
type CompleteObserver = {
complete(): void;
};
class Notification<T> {
observe(observer: NextObserver<T> | ErrorObserver | CompleteObserver): any {...}
} How about this? |
would you able to elaborate bit more details of reason |
As my thought, |
I pushed a new patch and changed this pull request's title. @Blesh @kwonoj @david-driscoll how don you think about this new change? |
My personal take on this is, revised interface does not gives clarity. Previous signature explicitly requires For same reason, |
…tially implemented observer
Umm, I'll reorganize.
By these points, we should take a To follow the v5's type definitions strictly, we also need to check As my thought, we don't have to check |
…ke a partially implemented observer" This reverts commit 63345d3.
I'm bit fence on this, this provides more strict type guarding means bringing additional checkers. Wish do we have some numbers to compare with. In any case, @saneyuki , I think commit history need to be aligned to remove some of previous commit (i.e, Revert ....) |
I have an alternative PR that I think fits a little nicer into what we should do with |
#1282 would be more good place for the discussion. I'll close this. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
No description provided.