Closed
Description
Bug Report
π Search Terms
- never
- class
- function
π Version & Regression Information
- Version: 5.0.4
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about
never
type and class
β― Playground Link
Playground link with relevant code
π» Code
function throwErrorFunction() : never {
throw new Error("Error in function")
}
class ErrorService {
throwErrorClass(): never {
throw new Error("Error in class")
}
}
function neverNotWorkingAsExpected() {
const errorService = new ErrorService();
errorService.throwErrorClass();
// The following line should be detected as unreachable
throwErrorFunction();
}
function neverWorkingAsExpected() {
throwErrorFunction();
// The following code is detected as unreachable
const errorService = new ErrorService();
errorService.throwErrorClass();
}
π Actual behavior
Code following a function of a class of type 'never' is not considered inaccessible.
It does not have the same behavior as a function that is not in a class.
π Expected behavior
The never
type is correctly handled when used in a function of a class.
So after using the function, the following code is considered unreachable.