However, due to current weakness in TypeScript, static reasoning
is less powerful with the || patterns than with an assert call.
Until/unless https://github.com/microsoft/TypeScript/issues/51426 is fixed,
for ||-style assertions where this loss of static reasoning is a problem,
instead express the assertion as
if (!condition) { Fail`...complaint...`; }
or, if needed,
if (!condition) { // `throw` is noop since `Fail` throws, but it improves static analysis throwFail`...complaint...`; }
Use the
Fail
function as a template literal tag to efficiently create and throw adetails
-style error only when a condition is not satisfied.This avoids the overhead of creating usually-unnecessary errors like
while improving readability over alternatives like
However, due to current weakness in TypeScript, static reasoning is less powerful with the
||
patterns than with anassert
call. Until/unless https://github.com/microsoft/TypeScript/issues/51426 is fixed, for||
-style assertions where this loss of static reasoning is a problem, instead express the assertion asor, if needed,