getOrThrow()'s new never-receiver gate produces an inscrutable diagnostic
Summary
5.0 gates getOrThrow() off when the Err channel is already empty:
getOrThrow(this: [E] extends [never] ? never : Result<T, E>): T;
The intent is right — once every Err is folded there is nothing to throw, so .get() is the
correct call. But the diagnostic the user actually sees says none of that:
TS2684: The 'this' context of type 'AsyncResult<void, never>' is not assignable
to method's 'this' of type 'never'.
Nothing there mentions .get(), or even hints that the emptiness of the error channel is the
reason. The first few occurrences read like a bug in the library rather than a deliberate gate.
Suggested fix
Brand the never with a message, the way a non-exhaustive ts-pattern match does:
getOrThrow(this: [E] extends [never]
? "getOrThrow is unnecessary: the Err channel is empty — use get() instead"
: AsyncResult<T, E>): Promise<T>;
TypeScript then prints the sentence as part of the mismatch, which is self-explanatory.
For contrast, the sibling gate on .get() (this: Result<T, never>) is much easier to read
because the required type is a real Result type — it is only the never receiver that
produces an opaque message.
Context
6 call sites in an 18-package monorepo upgrading 4.3.0 → 5.0.0-beta.4. Each one took a minute to
interpret the first time; all six were legitimate .get() conversions.
Environment
[email protected], TypeScript 7.0.1-rc