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

fix(compiler-cli): suppress unnecessary optional chain for indexed accesses #47218

Closed
wants to merge 1 commit into from

Conversation

JoostK
Copy link
Member

@JoostK JoostK commented Aug 22, 2022

TypeScript's type system does not include undefined in the type of an indexed
access, whereas array index accesses may be expected to be out-of-bounds.
This commit updates the extended diagnostic for unnecessary optional chains to
ignore indexed accesses.

Closes #46918

…cesses

TypeScript's type system does not include `undefined` in the type of an indexed
access, whereas array index accesses may be expected to be out-of-bounds.
This commit updates the extended diagnostic for unnecessary optional chains to
ignore indexed accesses.

Closes angular#46918
@JoostK JoostK added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release area: compiler Issues related to `ngc`, Angular's template compiler compiler: extended diagnostics labels Aug 22, 2022
@ngbot ngbot bot modified the milestone: Backlog Aug 22, 2022
@jelbourn
Copy link
Member

Copying discussion we had on Slack:
My thinking was that for arrays, you should only get undefined out of an array in two conditions:

  • a sparse array
  • array index out of bounds

For sparse arrays, you should manually type your array to include | undefined.

For array index out of bounds, you want to throw a real error and not let the program silently propagate undefined.

@JoostK JoostK closed this Oct 19, 2023
@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 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: review The PR is still awaiting reviews from at least one requested reviewer area: compiler Issues related to `ngc`, Angular's template compiler compiler: extended diagnostics target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

extended diagnostic for non-nullable optional is wrong
2 participants