Suggestion
🔍 Search Terms
return never tagged template unreachable code
Related issues:
#32695
#50363
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
Control flow analysis detecting unreachable code after a tagged template function call that throws.
📃 Motivating Example
It's a surprise that the same function call does not have control flow analysis when used as a tagged template:
function throws(opt?: any): never {
throw new Error()
}
function testFn() {
throws(`reason`);
// @ts-expect-error unreachable
console.log("is unreachable!")
}
function testTag() {
throws`reason`;
// ts does not detect that this is unreachable
console.log("is unreachable!")
}
(playground)
💻 Use Cases
Throwing an exception with a message
Normally this would be something like,
assert(condition, 'explanation');
However for performance reasons we eschew the function call:
condition || Fail`explanation`;
The asserts works but the Fail doesn't. We could work around this by Fail('explanation') but we prefer to be consistent in use of the Fail function. So for our current work-around is to explicitly throw the tagged template.
Suggestion
🔍 Search Terms
return never tagged template unreachable code
Related issues:
#32695
#50363
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
Control flow analysis detecting unreachable code after a tagged template function call that throws.
📃 Motivating Example
It's a surprise that the same function call does not have control flow analysis when used as a tagged template:
(playground)
💻 Use Cases
Throwing an exception with a message
Normally this would be something like,
However for performance reasons we eschew the function call:
The
assertsworks but theFaildoesn't. We could work around this byFail('explanation')but we prefer to be consistent in use of theFailfunction. So for our current work-around is to explicitlythrowthe tagged template.