Back to Type Challenges

README

questions/25747-hard-isnegativenumber/README.md

latest1.5 KB
Original Source
<!--info-header-start--><h1>IsNegativeNumber </h1><blockquote><p>by andrew jarrett <a href="https://github.com/ahrjarrett" target="_blank">@ahrjarrett</a></p></blockquote><p><a href="https://tsch.js.org/25747/play" target="_blank"></a> </p><!--info-header-end-->

Sometimes when working with numeric literals, we need to rule out (or enforce) that the provided number is a positive integer.

To do that, we first need a way to tell if the number is negative.

Write a type-level function IsNegativeNumber that accepts a number N and returns:

  • true if N is negative
  • false if N is positive
  • false if N is 0,
  • never if N is number
  • never if N is a union
<!--info-footer-start-->

<a href="../../README.md" target="_blank"></a> <a href="https://tsch.js.org/25747/answer" target="_blank"></a> <a href="https://tsch.js.org/25747/solutions" target="_blank"></a> <!--info-footer-end-->