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

Post strictPropertyInitialization flag flip cleanup #24571

Open
rkirov opened this issue Jun 18, 2018 · 7 comments
Open

Post strictPropertyInitialization flag flip cleanup #24571

rkirov opened this issue Jun 18, 2018 · 7 comments
Labels
area: core Issues related to the framework runtime freq2: medium P4 A relatively minor issue that is not relevant to core functions type: bug/fix
Projects
Milestone

Comments

@rkirov
Copy link
Contributor

rkirov commented Jun 18, 2018

I'm submitting a...

[x] Other... Please describe: Tracking issue for internal cleanup.

What needs to be done

In order to quickly turn on strictPropertyInitialization flag in the whole code base, we introduced ! on every non-initialized class field. Each one of those fields needs to be individually checked and decided whether:

  • the field should be initialized. Thus foo!: string, should become foo = 'default'.
  • the field should be marked as optional. Thus foo!: string, should become foo?: string.
  • the field is reliably initialized, but TS cannot infer that (initialization can occur outside the ctor, for example), so ! should be kept.
@alan-agius4
Copy link
Contributor

alan-agius4 commented Jul 3, 2018

@rkirov when an input is required, would you mark with a band !? As in my option in you don't know that the consumer will provide that value, thus, a component should be doing check if that value has been actually provided or not. ! should only be used if the value is initialised such as on ngOnInit. that said though, if one used that component using the viewChild etc... the property will be marked that it will never be undefined. Which in some cases it might be wrong, based on which lifecycle hook the value is initialized in.

And seeing the comment from @mhevery in #21571 it seems that we are on the same page;

Nothing forces @input() to be set. A user of the your component may simply chose not to bind to that input in which case your @input() is not initialize and you should have checks for non-initialized case. I know we disagree, but I think this is the correct behavior.

Truth to the told I am not a particular fan of using the !

@rkirov
Copy link
Contributor Author

rkirov commented Jul 12, 2018

If you want to have required semantics for your Inputs what we have been recommending is ! and an assert in ngOnInit. If are to be pedantic the assert should be in ngOnChanges, but that might be too much for some.

The general advice for ! in any place (on expressions or in field declarations names) is that it is unsafe and to be avoided unless there is a compelling reason.

I have an additional advice on cleaning up after my change specifically for angular components.

For Angular components

For angular components, use the following rules in deciding between:
a) adding initializer
b) make the field optional
c) leave the '!'

  • If the field is annotated with @input - Make the field optional b) or add an initializer a).
  • If the input is required for the component user - add an assertion in ngOnInit and apply c.
  • If the field is annotated @ViewChild, @ContentChild - Make the field optional b).
  • If the field is annotated with @ViewChildren or @ContentChildren - Add back '!' - c).
  • Fields that have an initializer, but it lives in ngOnInit. - Move the initializer to the constructor.
  • Fields that have an initializer, but it lives in ngOnInit and cannot be moved because it depends on other @input fields - Add back '!' - c).

@alan-agius4
Copy link
Contributor

alan-agius4 commented Jul 12, 2018

Thanks for the detailed explanation much appreciated.

I quite like what you suggest above.

@ngbot ngbot bot modified the milestones: needsTriage, Backlog Jul 12, 2018
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Jan 21, 2019
When we added the strict null checks, the lexer had some `!`
operators added to prevent the compilation from failing.

This commit resolves this problem correctly and removes the
hacks.

Also the comment

```
// Note: this is always lowercase!
```

has been removed as it is no longer true.

See angular#24571
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Jan 22, 2019
When we added the strict null checks, the lexer had some `!`
operators added to prevent the compilation from failing.

This commit resolves this problem correctly and removes the
hacks.

Also the comment

```
// Note: this is always lowercase!
```

has been removed as it is no longer true.

See angular#24571
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Jan 24, 2019
When we added the strict null checks, the lexer had some `!`
operators added to prevent the compilation from failing.

This commit resolves this problem correctly and removes the
hacks.

Also the comment

```
// Note: this is always lowercase!
```

has been removed as it is no longer true.

See angular#24571
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Jan 26, 2019
When we added the strict null checks, the lexer had some `!`
operators added to prevent the compilation from failing.

This commit resolves this problem correctly and removes the
hacks.

Also the comment

```
// Note: this is always lowercase!
```

has been removed as it is no longer true.

See angular#24571
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Jan 29, 2019
When we added the strict null checks, the lexer had some `!`
operators added to prevent the compilation from failing.

This commit resolves this problem correctly and removes the
hacks.

Also the comment

```
// Note: this is always lowercase!
```

has been removed as it is no longer true.

See angular#24571
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Jan 31, 2019
When we added the strict null checks, the lexer had some `!`
operators added to prevent the compilation from failing.

This commit resolves this problem correctly and removes the
hacks.

Also the comment

```
// Note: this is always lowercase!
```

has been removed as it is no longer true.

See angular#24571
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Feb 6, 2019
When we added the strict null checks, the lexer had some `!`
operators added to prevent the compilation from failing.

This commit resolves this problem correctly and removes the
hacks.

Also the comment

```
// Note: this is always lowercase!
```

has been removed as it is no longer true.

See angular#24571
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Feb 7, 2019
When we added the strict null checks, the lexer had some `!`
operators added to prevent the compilation from failing.

This commit resolves this problem correctly and removes the
hacks.

Also the comment

```
// Note: this is always lowercase!
```

has been removed as it is no longer true.

See angular#24571
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Feb 8, 2019
When we added the strict null checks, the lexer had some `!`
operators added to prevent the compilation from failing.

This commit resolves this problem correctly and removes the
hacks.

Also the comment

```
// Note: this is always lowercase!
```

has been removed as it is no longer true.

See angular#24571
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Feb 8, 2019
When we added the strict null checks, the lexer had some `!`
operators added to prevent the compilation from failing.

This commit resolves this problem correctly and removes the
hacks.

Also the comment

```
// Note: this is always lowercase!
```

has been removed as it is no longer true.

See angular#24571
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Feb 8, 2019
When we added the strict null checks, the lexer had some `!`
operators added to prevent the compilation from failing.

This commit resolves this problem correctly and removes the
hacks.

Also the comment

```
// Note: this is always lowercase!
```

has been removed as it is no longer true.

See angular#24571
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Feb 8, 2019
When we added the strict null checks, the lexer had some `!`
operators added to prevent the compilation from failing.

This commit resolves this problem correctly and removes the
hacks.

Also the comment

```
// Note: this is always lowercase!
```

has been removed as it is no longer true.

See angular#24571
kara pushed a commit to petebacondarwin/angular that referenced this issue Feb 12, 2019
When we added the strict null checks, the lexer had some `!`
operators added to prevent the compilation from failing.

This commit resolves this problem correctly and removes the
hacks.

Also the comment

```
// Note: this is always lowercase!
```

has been removed as it is no longer true.

See angular#24571
mhevery pushed a commit that referenced this issue Feb 13, 2019
When we added the strict null checks, the lexer had some `!`
operators added to prevent the compilation from failing.

This commit resolves this problem correctly and removes the
hacks.

Also the comment

```
// Note: this is always lowercase!
```

has been removed as it is no longer true.

See #24571

PR Close #28055
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Feb 14, 2019
…lar#28055)

When we added the strict null checks, the lexer had some `!`
operators added to prevent the compilation from failing.

This commit resolves this problem correctly and removes the
hacks.

Also the comment

```
// Note: this is always lowercase!
```

has been removed as it is no longer true.

See angular#24571

PR Close angular#28055
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Mar 4, 2019
…lar#28055)

When we added the strict null checks, the lexer had some `!`
operators added to prevent the compilation from failing.

This commit resolves this problem correctly and removes the
hacks.

Also the comment

```
// Note: this is always lowercase!
```

has been removed as it is no longer true.

See angular#24571

PR Close angular#28055
AndrewKushnir pushed a commit that referenced this issue Mar 4, 2019
…) (#28736)

When we added the strict null checks, the lexer had some `!`
operators added to prevent the compilation from failing.

This commit resolves this problem correctly and removes the
hacks.

Also the comment

```
// Note: this is always lowercase!
```

has been removed as it is no longer true.

See #24571

PR Close #28055

PR Close #28736
@a-deeb
Copy link

a-deeb commented Mar 23, 2019

Hi, I am fairly new to Github but would like to help out, I see a lot of files that have // TODO(issue/24571): remove '!'. in them, I would like to know how would I go about making changes in this file for example : angular/packages/core/test/linker/query_integration_spec.ts and angular/packages/upgrade/src/common/component_info.ts .
Thanks !

JeanMeche added a commit to JeanMeche/angular that referenced this issue Feb 27, 2023
This commit removes the remaining TODO(issue/24571) in elements code base.
JeanMeche added a commit to JeanMeche/angular that referenced this issue Feb 27, 2023
This commit removes the remaining TODO(issue/24571) in examples code base.
JeanMeche added a commit to JeanMeche/angular that referenced this issue Feb 27, 2023
This commit removes the remaining TODO(issue/24571) in platform-server code base.
JeanMeche added a commit to JeanMeche/angular that referenced this issue Feb 27, 2023
As part of angular#24571, removing all non-null assertions from common/http
JeanMeche added a commit to JeanMeche/angular that referenced this issue Feb 27, 2023
As part of angular#24571, removing all non-null assertions from common/http
JeanMeche added a commit to JeanMeche/angular that referenced this issue Feb 27, 2023
This commit removes the remaining ones in animations code base
JeanMeche added a commit to JeanMeche/angular that referenced this issue Feb 27, 2023
This commit removes the remaining TODO(issue/24571) in platform-server code base.
JeanMeche added a commit to JeanMeche/angular that referenced this issue Feb 27, 2023
This commit removes the remaining TODO(issue/24571) in platform-server code base.
AndrewKushnir pushed a commit that referenced this issue Feb 28, 2023
This commit removes the remaining TODO(issue/24571) in elements code base.

PR Close #49233
AndrewKushnir pushed a commit that referenced this issue Feb 28, 2023
This commit removes the remaining TODO(issue/24571) in platform-server code base.

PR Close #49233
AndrewKushnir pushed a commit that referenced this issue Feb 28, 2023
This commit removes the remaining TODO(issue/24571) in elements code base.

PR Close #49233
AndrewKushnir pushed a commit that referenced this issue Feb 28, 2023
This commit removes the remaining TODO(issue/24571) in platform-server code base.

PR Close #49233
JeanMeche added a commit to JeanMeche/angular that referenced this issue Mar 4, 2023
This commit removes the remaining TODO(issue/24571) in platform-browser code base.
JeanMeche added a commit to JeanMeche/angular that referenced this issue Mar 5, 2023
This commit removes the remaining TODO(issue/24571) in platform-browser code base.
jessicajaniuk pushed a commit that referenced this issue Mar 6, 2023
This commit removes the remaining TODO(issue/24571) in platform-browser code base.

PR Close #49232
jessicajaniuk pushed a commit that referenced this issue Mar 6, 2023
This commit removes the remaining TODO(issue/24571) in platform-browser code base.

PR Close #49232
jessicajaniuk pushed a commit that referenced this issue Mar 6, 2023
This commit removes the remaining ones in animations code base

PR Close #49231
jessicajaniuk pushed a commit that referenced this issue Mar 6, 2023
This commit removes the remaining ones in animations code base

PR Close #49231
AndrewKushnir pushed a commit to JeanMeche/angular that referenced this issue Apr 18, 2023
This commit removes the remaining TODO(issue/24571) in compiler code base.
jessicajaniuk pushed a commit that referenced this issue Apr 18, 2023
This commit removes the remaining TODO(issue/24571) in compiler code base.

PR Close #49220
jessicajaniuk pushed a commit that referenced this issue Apr 18, 2023
This commit removes the remaining TODO(issue/24571) in compiler code base.

PR Close #49220
JeanMeche added a commit to JeanMeche/angular that referenced this issue Jun 6, 2023
This commit removes the remaining TODO(issue/24571) in core code base.
JeanMeche added a commit to JeanMeche/angular that referenced this issue Jun 6, 2023
This commit removes the remaining TODO(issue/24571) in core code base.
JeanMeche added a commit to JeanMeche/angular that referenced this issue Jun 7, 2023
This commit removes the remaining TODO(issue/24571) in core code base.
JeanMeche added a commit to JeanMeche/angular that referenced this issue Jun 14, 2023
This commit removes the remaining TODO(issue/24571) in core code base.
pkozlowski-opensource pushed a commit that referenced this issue Jun 14, 2023
This commit removes the remaining TODO(issue/24571) in core code base.

PR Close #49221
pkozlowski-opensource pushed a commit that referenced this issue Jun 14, 2023
This commit removes the remaining TODO(issue/24571) in core code base.

PR Close #49221
thomasturrell pushed a commit to thomasturrell/angular that referenced this issue Aug 29, 2023
This commit removes the remaining TODO(issue/24571) in core code base.

PR Close angular#49221
ChellappanRajan pushed a commit to ChellappanRajan/angular that referenced this issue Jan 23, 2024
This commit removes the remaining TODO(issue/24571) in core code base.

PR Close angular#49221
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: core Issues related to the framework runtime freq2: medium P4 A relatively minor issue that is not relevant to core functions type: bug/fix
Projects
docs
Committed - Selected for development
8 participants