You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"never function not inferred", "async function never return type", "cross-module never return inference", "throw function doesn't stop execution", "ApolloError inferred as possible return"
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about control flow inference across modules and never functions.
TypeScript does not understand that throwTypedError() will never return. Even though the return type is correctly typed as never, and it throws immediately, the compiler still demands a return statement after it — especially in async functions returning Promise.
This happens only when the function is imported from another file or module. If the same function is inlined, TS understands the control flow and does not require the extra return.
🙂 Expected behavior
TypeScript should propagate the never type properly across modules and treat throwTypedError() as the termination of the control flow path. No further return or unreachable code warning should be necessary after such calls.
Additional information about the issue
This limitation affects async services that call reusable throw functions, such as throwErrorHandler(...) in systems like Apollo GraphQL, resulting in unnecessary boilerplate return undefined as never statements or unreachable code just to satisfy the compiler.
We understand this might be a deep inference challenge across modules, but a fix or compiler hint (@terminates, @NoReturn, etc.) would improve developer ergonomics.
The text was updated successfully, but these errors were encountered:
TypeScript does not understand that throwTypedError() will never return.
There is no such function in your code. If you actually mean throwErrorHandler, then this is working and completely unrelated to modules or async. The behavior will be the same within the same file.
The problem is that when you have an asynchronous function from another module that returns never, TypeScript ignores this fact and gives a typing error right below the call.
🔎 Search Terms
"never function not inferred", "async function never return type", "cross-module never return inference", "throw function doesn't stop execution", "ApolloError inferred as possible return"
🕗 Version & Regression Information
never
functions.⏯ Playground Link
No response
💻 Code
🙁 Actual behavior
TypeScript does not understand that throwTypedError() will never return. Even though the return type is correctly typed as never, and it throws immediately, the compiler still demands a return statement after it — especially in async functions returning Promise.
This happens only when the function is imported from another file or module. If the same function is inlined, TS understands the control flow and does not require the extra return.
🙂 Expected behavior
TypeScript should propagate the never type properly across modules and treat throwTypedError() as the termination of the control flow path. No further return or unreachable code warning should be necessary after such calls.
Additional information about the issue
This limitation affects async services that call reusable throw functions, such as throwErrorHandler(...) in systems like Apollo GraphQL, resulting in unnecessary boilerplate return undefined as never statements or unreachable code just to satisfy the compiler.
We understand this might be a deep inference challenge across modules, but a fix or compiler hint (@terminates, @NoReturn, etc.) would improve developer ergonomics.
The text was updated successfully, but these errors were encountered: