Skip to content
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

feat(common): allow any Subscribable in async pipe #39627

Closed
wants to merge 1 commit into from

Conversation

divdavem
Copy link
Contributor

As only methods from the Subscribable interface are currently used in the implementation of the async pipe, it makes sense to make it explicit so that it works successfully (regarding type-checking) with any other implementation instead of only Observable.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

The following component does not compile successfully:

import { Component, Input } from '@angular/core';
import { Subscribable } from 'rxjs';

@Component({
  selector: 'hello',
  template: `Hello {{ nameSubscribable | async }}`
})
export class HelloComponent  {
  @Input() nameSubscribable: Subscribable<any>;
  // Note that it works fine when replacing the above line with:
  // @Input() nameSubscribable: any;
}

Here is the compilation error:

No overload matches this call.
The last overload gave the following error.
Argument of type 'Subscribable<any>' is not assignable to parameter of type 'Promise<unknown>'.
Type 'Subscribable<any>' is missing the following properties from type 'Promise<unknown>': then, catch, [Symbol.toStringTag], finally

(cf https://stackblitz.com/edit/angular-ivy-fypzxs?file=src/app/hello.component.ts )

What is the new behavior?

The compilation of the previous component is successful.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

The important part of this PR is about changing the input type from Observable to Subscribable in async pipe.
For consistency, I have renamed some local variables to contain subscribable instead of observable.
In packages/core/src/util/lang.ts, I have added the isSubscribable function that does the same thing as isObservable but, in case the TODO mentioned in isObservable is implemented those two methods would be different.

@google-cla google-cla bot added the cla: yes label Nov 10, 2020
@petebacondarwin
Copy link
Member

This is an interesting idea, but I want to check with the rest of the team before making any decision on whether to go ahead with this.

@divdavem divdavem marked this pull request as ready for review November 12, 2020 08:57
@atscott
Copy link
Contributor

atscott commented Nov 12, 2020

This is an interesting idea, but I want to check with the rest of the team before making any decision on whether to go ahead with this.

Agreed that this seems totally reasonable and straightforward. Because it actually expands the type rather than narrowing it, I believe this is a non-breaking change (triggered presubmit as a sanity check) and I can't think of any good reason not to move forward with it. I suppose there's a question as to why this change is necessary since I can't say I've ever encountered anyone asking for this feature (other than now).

Copy link
Contributor

@atscott atscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As expected, the presubmit doesn't have any failures related to this change. I'm in favor of moving this forward. As I said before, I can't think of any reason to not allow Subscribable since it really is already supported as the pipe is implemented; the type just needs to accurately reflect the wider range of supported inputs.

Copy link
Contributor

@IgorMinar IgorMinar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks good to me from the API perspective. Thanks

Reviewed-for: public-api

@atscott atscott added the target: minor This PR is targeted for the next minor release label Nov 13, 2020
Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for dev-infra

Reviewed-for: dev-infra

packages/core/src/util/lang.ts Show resolved Hide resolved
packages/common/test/pipes/async_pipe_spec.ts Outdated Show resolved Hide resolved
packages/common/test/pipes/async_pipe_spec.ts Show resolved Hide resolved
@AndrewKushnir AndrewKushnir added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Nov 19, 2020
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-for: public-api

FYI, I've also added the "cleanup" label since there is a merge conflict with the master branch. Feel free to remove it once the conflict is resolved. Thank you.

As only methods from the Subscribable interface are currently used in the
implementation of the async pipe, it makes sense to make it explicit so
that it works successfully with any other implementation instead of
only Observable.
@divdavem
Copy link
Contributor Author

@AndrewKushnir @gkalpak @IgorMinar @atscott Thank you for your review 👍

I do not have the ability to remove the cleanup label, but I have rebased the PR to solve the conflict with the master branch and done a few changes as requested by @gkalpak
I suppose the PR is ready to be merged, unless you have any other comment.

@gkalpak gkalpak added action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Nov 20, 2020
Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-for: public-api

@AndrewKushnir AndrewKushnir added the action: presubmit The PR is in need of a google3 presubmit label Nov 20, 2020
@AndrewKushnir
Copy link
Contributor

AndrewKushnir commented Nov 21, 2020

Presubmit + Global Presubmit.

@AndrewKushnir AndrewKushnir removed the action: presubmit The PR is in need of a google3 presubmit label Nov 23, 2020
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 24, 2020
@pullapprove pullapprove bot added area: common Issues related to APIs in the @angular/common package area: core Issues related to the framework runtime area: dev-infra Issues related to Angular's own dev infra (build, test, CI, releasing) comp: docs/api labels Dec 24, 2020
@ngbot ngbot bot modified the milestone: Backlog Dec 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: common Issues related to APIs in the @angular/common package area: core Issues related to the framework runtime area: dev-infra Issues related to Angular's own dev infra (build, test, CI, releasing) cla: yes cross-cutting: types state: needs eng input target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants