Skip to content

never type does not work as expected in the function of a classΒ #54265

Closed
@SkyGrasperKnight

Description

@SkyGrasperKnight

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions