Closed
Description
Before You File a Proposal Please Confirm You Have Done The Following...
- I have searched for related issues and found none that match my proposal.
- I have searched the current rule list and found no rules that match my proposal.
- I have read the FAQ and my problem is not listed.
My proposal is suitable for this project
- I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).
Link to the rule's documentation
https://typescript-eslint.io/rules/strict-boolean-expressions/
Description
For example, ok
from node:assert
has the following shape:
function ok(value: unknown, message?: string | Error): asserts value;
It appears that currently the rule just looks at value
, sees unknown
, and moves on. So it's possible to write this:
const foo: string | undefined = 'bar';
if (foo) ... // Error
ok(foo); // Fine
Instead, it would be nice if it also looked at the return type and took asserts value
into account, treating it as if (!value) throw
. There's more to asserts
than just checking truthiness, but handling the simplest case (no is
) would already go a long way, as that covers all ok
-like assertion functions out there.
Fail
const foo: string | undefined = 'bar';
ok(foo);
Pass
const foo: string | undefined = 'bar';
ok(foo !== undefined);
Additional Info
No response