Hacker News new | ask | show | jobs
by spoiler 1917 days ago
You're correct that this generates a false-positive! This is a really interesting feature. Would love to see more static analysers/compilers implement this.

You might be aware already, but the examples aren't the same (I know it illustrated the same idea tho) as on the Psalm post. It might make sense to align them with the PHP example so people don't get tripped up on that (esp if they're not too familiar with TS and PHP quirks)! Additionally `!a` and `a !== null` (or `!=`) aren't the same in JS/TS, so maybe change those in your example too, just to get your point across better.

BTW, Psalm seems really cool! I've not used PHP in a long time, but I always felt it lacks tooling, so it's great to see people are making progress in that area. Keep up the good work!

1 comments

> You might be aware already, but the examples aren't the same

Yeah, because both TS and PHP have the same treatment of `!expr` I use the two interchangeably when demonstrating functionality, but the exactly comparable example is here:

https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABMO...

> BTW, Psalm seems really cool! I've not used PHP in a long time, but I always felt it lacks tooling, so it's great to see people are making progress in that area.

Yeah, it's not the only open-source static analysis tool for PHP – there's also https://phpstan.org, which is even more popular