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

Proposal: emit warning or error when coercing array to boolean #14638

Closed
realyze opened this issue Mar 13, 2017 · 8 comments
Closed

Proposal: emit warning or error when coercing array to boolean #14638

realyze opened this issue Mar 13, 2017 · 8 comments
Labels
Duplicate An existing issue was already created

Comments

@realyze
Copy link

realyze commented Mar 13, 2017

[email protected]

This snippet compiles without any warning:

const result: string[] = gimmeResult(); // returns an array type
if (!result) { 
 // code
}

And I'd argue it's almost always a masked bug (the programmer did not realise the return value was an array).

Would it be sensible to emit some sort of a warning?

@mhegazy
Copy link
Contributor

mhegazy commented Mar 13, 2017

and if (result) { .. is not allowed either?

@RyanCavanaugh
Copy link
Member

Duplicate #9041 ?

@RyanCavanaugh
Copy link
Member

Or #14114

@realyze
Copy link
Author

realyze commented Mar 13, 2017

@mhegazy Yeah, good point. :-) I would say any array -> boolean coercion is a code smell and most probably a bug.

@RyanCavanaugh Thanks. Man, you must have a really good memory. :-D

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

I just keep all the issue numbers scrawled on a scrap of paper near my desk 😉

@aluanhaddad
Copy link
Contributor

@RyanCavanaugh the hyperspace In | n ∈ Z ≥ 14638 over the field of Typescript issues reduced to a single flat physical object 😲

@realyze
Copy link
Author

realyze commented Mar 14, 2017

@RyanCavanaugh Man, you must have a really large desk. :)

@realyze
Copy link
Author

realyze commented Mar 14, 2017

At work:

image

...sorry couldn't help it, I'll stop spamming now :-)

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 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