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

Array.prototype.filter misses undefined in returning value #18760

Closed
ezubarev opened this issue Sep 26, 2017 · 4 comments
Closed

Array.prototype.filter misses undefined in returning value #18760

ezubarev opened this issue Sep 26, 2017 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@ezubarev
Copy link

TypeScript Version: 2.4.0

Code

const values = [1, 2];
values.filter((value) => value === 3)[0];

Expected behavior:
Object is possibly 'undefined'.

Actual behavior:
No errors.

@aluanhaddad
Copy link
Contributor

The type of values is number[] not [number, number] or [1, 2]. Even if tuple types were used however, this still would not be an error.

See #6229

@ezubarev
Copy link
Author

values.filter((value) => value === 3) is undefined in this case. It doesn't link with provided issue.

@kitsonk
Copy link
Contributor

kitsonk commented Sep 26, 2017

Duplicate of #13778

It is a conscious decision to favour usability over correctness, though the linked issue indicates it is open for further discussion.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Sep 26, 2017
@RyanCavanaugh
Copy link
Member

We assume that you are bounds-checking yourself correctly since the alternative is quite a bit worse. See linked issues above.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants