Closed as not planned
Description
Suggestion
Right now our nullThrows
utility has signature like so:
declare function nullThrows<T>(x: T, reason: string): NonNullable<T>;
which basically models a runtime non-null assertion operator x!
.
However, unlike the non-null assertion operator, we don't have a way to flag when the argument provided is already non-null
const nonNull = 'foo';
const foo1 = nonNull!; // violates no-unnecessary-type-assertion
const foo2 = nullThrows(foo1, 'reason'); // no linter report.
We could pretty easily right our own custom rule in order to flag this scenario, however, now that #10009 has landed, I propose let's change the signature to be an assertion function so that we can dogfood no-unnecessary-condition's checkTypePredicates
functionality.
declare function nullThrows<T>(x: T, reason: string): asserts x is NonNullable<T>;
const nonNull = 'foo';
nullThrows(nonNull, 'reason'); // no-unnecessary-condition - types are already equal
Additional Info
No response