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

Compiler option for stricter implicit truthy and falsy checks #8178

Closed
ziriax opened this issue Apr 19, 2016 · 2 comments
Closed

Compiler option for stricter implicit truthy and falsy checks #8178

ziriax opened this issue Apr 19, 2016 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@ziriax
Copy link

ziriax commented Apr 19, 2016

We have a large Typescript application, and sometimes we have code like

if (shouldFireNuclearMissiles)...

while we should have written

if (shouldFireNuclearMissiles())...

(pun intended).

So forgetting to evaluate a function results in a truthy value.

I forked the tsc compiler to add basic checks for this in the conditional operator, the if-then-else, while, do and for statements, and that was very easy. We found several bugs in our large code using this forked compiler.

Would such a stricter compiler option (maybe even emitting warnings) be a sound idea?

These automatic truthy and falsy conversions are very handy, but IMHO, for large projects, the comfort they bring does not outweigh the dangers.

Most likely this idea is too much non-Javascript-like, but we're coming from sharp & strongly-typed languages, so I must make this suggestion ;-)

Thanks,
Peter

PS: I first suggested this as a TSLINT rule , but from the friendly feedback I got, it seems this belongs in the compiler instead.

@myitcv
Copy link

myitcv commented Apr 19, 2016

Covered here palantir/tslint#253 in the actual tslint repository

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Apr 19, 2016
@RyanCavanaugh
Copy link
Member

Duplicate of #7306

@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

3 participants