Skip to content

fix(@angular/cli): Do not use floating promises, we can resolve these… #17652

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

Closed

Conversation

timfrijtersppw
Copy link
Contributor

In this PR I've fixed some floating promises in the generation of component spec files and app.component.spec.ts.

Without this fix tslint errors occur when generating components when the tslint option 'no-floating-promises' is enabled.

Also see:
https://palantir.github.io/tslint/rules/no-floating-promises/

@timfrijtersppw timfrijtersppw force-pushed the fix-promise-handling branch from 4573010 to e948768 Compare May 6, 2020 15:39
@timfrijtersppw
Copy link
Contributor Author

Please note that I've never really done an open source pull request before. If there is anything missing please let me know.

@timfrijtersppw timfrijtersppw force-pushed the fix-promise-handling branch from e948768 to b6f5bd4 Compare May 6, 2020 15:43
beforeEach(async(() => {
TestBed.configureTestingModule({<% if (routing) { %>
beforeEach(async () => {
return TestBed.configureTestingModule({<% if (routing) { %>
Copy link
Member

Choose a reason for hiding this comment

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

Is there any point in using async if you are not awaiting the promise?
I would expect either async () => { await TestBed... } or () => { return TestBed... }.

Copy link
Member

Choose a reason for hiding this comment

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

i'd probably go with await to make it more explicit that it is an asynchronous operation and also slightly simplify future user additions (either before or after the call).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think async shouldn't only be used when awaiting, returning the promise also showcases asynchronous behavior.

@@ -1,11 +1,11 @@
import { browser, by, element } from 'protractor';

export class AppPage {
navigateTo(): Promise<unknown> {
async navigateTo(): Promise<unknown> {
Copy link
Member

Choose a reason for hiding this comment

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

FWIW, you can also use PromiseLike<...> here and not have to cast below.
Do you know if there are any downsides to using PromiseLike?

Copy link
Member

@clydin clydin May 6, 2020

Choose a reason for hiding this comment

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

PromiseLike is mainly useful when dealing with alternative implementations of promises (bluebird, etc.). The only real downside is that it won't be accepted for any consumer that expects a Promise (e.g., function myFunc(p: Promise<unknown>) {}).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, no reason for async here since you are not using await.

@clydin
Copy link
Member

clydin commented Oct 6, 2020

Thank you for the contribution. This change has, however, been superseded by #18243 and #18951. Both of which will be available in the upcoming version 11.

@clydin clydin closed this Oct 6, 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 Nov 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants