-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed as not planned
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code
Description
🔎 Search Terms
- type narrowing
- return type never
- error
- throw
- method
- chaining
- error 7027
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for any entries relating to return type
never
⏯ Playground Link
💻 Code
const throwError = (message: string): never => {
throw new Error(message);
}
type Thrower = typeof throwError;
const errorContext = {
throwError
};
type ErrorContext = typeof errorContext;
const test1 = (thrower: Thrower) => {
throw new Error('foo');
// following code results in 7027 "unreachable code detected" as expected
console.log('bar');
};
const test2 = (thrower: Thrower) => {
thrower('foo');
// following code results in 7027 "unreachable code detected" as expected
console.log('bar');
};
const test3 = (errorContext: ErrorContext) => {
errorContext.throwError('foo');
// following code does NOT result in 7027, although the code is unreachable at runtime
console.log('bar');
};🙁 Actual behavior
If a function that returns never is a method, it does not result in error 7027 "unreachable code detected" or any
expected type-narrowing for subsequent code when called.
🙂 Expected behavior
Any code after a call to a function that always returns never should result in error 7027 "unreachable code detected" and any expected type-narrowing regardless of whether that function is method or a standalone function.
Additional information about the issue
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code