Skip to content

refactor(core): Replace non-null assertion operator with property initialization#34293

Closed
kubk wants to merge 1 commit intoangular:masterfrom
kubk:master
Closed

refactor(core): Replace non-null assertion operator with property initialization#34293
kubk wants to merge 1 commit intoangular:masterfrom
kubk:master

Conversation

@kubk
Copy link
Contributor

@kubk kubk commented Dec 7, 2019

Replace non-null assertion operator with property initialization.

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:

Does this PR introduce a breaking change?

  • Yes
  • No

@kubk kubk requested a review from a team December 7, 2019 11:22
@AndrewKushnir AndrewKushnir added the area: core Issues related to the framework runtime label Dec 11, 2019
@ngbot ngbot bot added this to the needsTriage milestone Dec 11, 2019
@mhevery mhevery added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Mar 6, 2020
@mhevery mhevery self-assigned this Mar 6, 2020
@mhevery
Copy link
Contributor

mhevery commented Mar 6, 2020

presubmit

@alfaproject
Copy link
Contributor

This increases bundle size for no actual benefit as far as I can see? It seems like a valid use of this TypeScript functionality.

Either that, or it should be | undefined and then the code adjusted for that.

@kubk
Copy link
Contributor Author

kubk commented Mar 7, 2020

@alfaproject Changing type to Function | undefined would require more code because the function type should be narrowed from Function | undefined to Function using if statements. Before:

this.resolve();

After:

if (this.resolve) {
  this.resolve();
}

The same applies to this.reject. Removing non-null assertion operator might prevent runtime errors in the future. There is a TSLint rule that describes the cons of this operator: https://palantir.github.io/tslint/rules/no-non-null-assertion/
The similar commits were already merged in the past: 1b0580a#diff-6a59e357bd47ab780ce7fcf88e9dfc50

@matsko
Copy link
Contributor

matsko commented Mar 9, 2020

@kubk please rebase.

@alfaproject
Copy link
Contributor

@kubk I mean generated code. Check the down-levelled version in ES5 (it also uses more memory, btw)

Not sure what's the problem in keeping the non-null assertion operator to keep it lean. It exists for a reason. I would just remove the TODO comments or replace them with a more descriptive comment of why it's ok to have it, but I'm not a maintainer d:

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

Hi @kubk, thanks for rebasing your PR. It looks like the integration_test is failing with payload size checks (see https://circleci.com/gh/angular/angular/648028#tests/containers/2). Could you please update the file mentioned in the error message? Thank you.

@kubk
Copy link
Contributor Author

kubk commented Mar 11, 2020

@AndrewKushnir Done. Do you know how to fix the rest of the issues?

@AndrewKushnir
Copy link
Contributor

Hi @kubk, it looks like CI errors are flakes, I've restarted failing CI jobs.

I've also added @kara as a reviewer for this PR, since it increases payload size limits.

Thank you.

@mhevery
Copy link
Contributor

mhevery commented Nov 18, 2020

Closing in favor of #39730

@mhevery mhevery closed this Nov 18, 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 19, 2020
@pullapprove pullapprove bot added the area: testing Issues related to Angular testing features, such as TestBed label Dec 19, 2020
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Dec 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews area: core Issues related to the framework runtime area: testing Issues related to Angular testing features, such as TestBed cla: yes target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants