We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
function member never ts2534
https://www.typescriptlang.org/play/?ts=5.7.0-dev.20240925#code/C4TwDgpgBAaghgGwJYBM7CQewHYDECu2AxhjlALxQAUAdHXAM4MQBOp2DAXFIQNbaYA7tgDaAXQCUFAHxQAbplQBuAFAqk2YKwBmcItHjI0WqBAAeW7CgaxEqdFjyESjqAG8VASF1IEVCdzYEHKsqgC+atrO7PJ2xhAAkpqs2Ii09Eys7Fw82PxCopLcCqjuXkja1ACEjMxsjgw0wawgVABCmJgIEHDYElIenp7AABYsQlBBglAAoizjLFQARHJxDmQ+3ShLEqqeEREqRDgMwLFG6NCUqxdaSVosqQg0AEYaKFSEKBDaGhAoUkYtluEFUN3sWhomwo1Ck5Fk4PiVF0CGYgJsfAEwigQKCIRYqki0Vcm38gWaLDKUHOEIgULgvn8qmpAHoWdSORyAHoAfhUhyixBiQVO-1wDL8AUmFLKnjZk0wpnmmEpI1YEC8pN2XnlvP5ahFWhQ4sZuyg8tGSBso3Gghs7wg-xUCEwAHNlihSgIzjahDtVEA
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");
TS complains about the never return type of function fail():
never
function fail()
A function returning 'never' cannot have a reachable end point.(2534)
No errors
No response
The text was updated successfully, but these errors were encountered:
This is working as intended / a design limitation. See #32695.
A function call is analyzed as an assertion call or never-returning call when the call occurs as a top-level expression statement, and the call specifies a single identifier or a dotted sequence of identifiers for the function name, and each identifier in the function name references an entity with an explicit type, and the function name resolves to a function type with an asserts return type or an explicit never return type annotation.
A function call is analyzed as an assertion call or never-returning call when
asserts
validate does not have an explicit type.
validate
Sorry, something went wrong.
Edit: I was too fast. Thanks for the update, it does work with an explicit type annotation on validate.
Is that because validate has no type annotation?
Correct, it has no explicit type. I just edited my comment to add that information. This limitation was added for performance reasons.
only-throw-error
No branches or pull requests
π Search Terms
function member never ts2534
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.7.0-dev.20240925#code/C4TwDgpgBAaghgGwJYBM7CQewHYDECu2AxhjlALxQAUAdHXAM4MQBOp2DAXFIQNbaYA7tgDaAXQCUFAHxQAbplQBuAFAqk2YKwBmcItHjI0WqBAAeW7CgaxEqdFjyESjqAG8VASF1IEVCdzYEHKsqgC+atrO7PJ2xhAAkpqs2Ii09Eys7Fw82PxCopLcCqjuXkja1ACEjMxsjgw0wawgVABCmJgIEHDYElIenp7AABYsQlBBglAAoizjLFQARHJxDmQ+3ShLEqqeEREqRDgMwLFG6NCUqxdaSVosqQg0AEYaKFSEKBDaGhAoUkYtluEFUN3sWhomwo1Ck5Fk4PiVF0CGYgJsfAEwigQKCIRYqki0Vcm38gWaLDKUHOEIgULgvn8qmpAHoWdSORyAHoAfhUhyixBiQVO-1wDL8AUmFLKnjZk0wpnmmEpI1YEC8pN2XnlvP5ahFWhQ4sZuyg8tGSBso3Gghs7wg-xUCEwAHNlihSgIzjahDtVEA
π» Code
π Actual behavior
TS complains about the
never
return type offunction fail()
:π Expected behavior
No errors
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: