Closed as not planned
Closed as not planned
Description
π Search Terms
function member never ts2534
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about never
β― Playground Link
π» Code
type ValidationFunction = (...assertions: unknown[]) => void;
interface Validate extends ValidationFunction {
fail(): never;
}
function validateInternal(...assertions: unknown[]): void {
if (!assertions.every(Boolean)) {
throw new Error("validation failed");
}
}
const validate = validateInternal.bind(undefined) as Validate;
validate.fail = () => validate(false) as unknown as never;
function fail(): never {
validate.fail();
// ^? (method) Validate.fail(): never
}
function nestedFail(): never {
// no error here
fail();
// ^? function fail(): never
}
nestedFail(); // this throws indeed
log("did not throw");
π Actual behavior
TS complains about the never
return type of function fail()
:
A function returning 'never' cannot have a reachable end point.(2534)
π Expected behavior
No errors
Additional information about the issue
No response
Metadata
Metadata
Assignees
Labels
No labels