you are viewing a single comment's thread
view the rest of the comments
[–] 8 points 11 months ago (2 children)

Because if it never returns, then it has no return value.

Then how would you annotate having no return value?

  • source
  • parent
  • hideshow 2 child comments
  • [–] 0 points 11 months ago (1 child)

    I guess it makes sense. What I struggled with is, as the type is unusable basically and I didn't like the idea it being a type. But for documentation reasons, it makes sense. Otherwise, it has no practical meaning. Even a comment could have the same effect.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 6 points 11 months ago

    The never type comes more from type theory and isn't common in other languages (though TS has never). Similar to 0 or the null set, it exists as a "base case" for types. For example, where you have unions of T1 | T2 | ..., the "empty union" is the never type. Similarly, for set theory, a union of no sets is the null set, and in algebra, the summation of no numbers is 0.

    In practice, because it can't be constructed, it can be used in unique ways. These properties happen to be super useful in niche places.

  • source
  • parent