Repository navigation
Warn on non-nullable optional chain #44870
Description
Activity
- addedfeatureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issuesarea: compilerIssues related to `ngc`, Angular's template compilerIssues related to `ngc`, Angular's template compiler
on Jan 28, 2022 This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.
You can find more details about the feature request process in our documentation.
Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.
Find more details about Angular's feature request process in our documentation.
Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.
We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.
You can find more details about the feature request process in our documentation.
angular-automatic-lock-bot commented
on Aug 12, 2022 More actionsThis 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.
- locked and limited conversation to collaborators
on Aug 12, 2022
Which @angular/* package(s) are relevant/releated to the feature request?
compiler-cli
Description
Optional chaining is a great way to safely access properties that might be
nullorundefined, for example:But things can easily change and make the optional chain useless, such as:
export class Greeter { - @Input() user?: User; + @Input() user: User; }This change means that the optional chain
user?.nameis no longer useful becauseuserwill never benullorundefined. This leads to confusion and tricks readers of the code into thinking that there is a case where "Hello, guest!" is displayed, when that actually isn't the case. If the default "guest" string comes from somewhere else, it could lead to dead code and possibly result in excess bundle size.Proposed solution
We should consider an extended diagnostic to identify and warn developers in this situation. We already have a diagnostic to warn about useless nullish coalescing operators
??, so it makes sense to have a similar check for optional chaining.Alternatives considered
N/A