Skip to content

Commit

Permalink
feat(question): add type-challenges#25747 - IsNegativeNumber (type-ch…
Browse files Browse the repository at this point in the history
…allenges#25748)

Co-authored-by: andrew jarrett <15133992+ahrjarrett@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and ahrjarrett authored Apr 2, 2023
1 parent 0246bc7 commit 3275c05
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions questions/25747-hard-isnegativenumber/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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
7 changes: 7 additions & 0 deletions questions/25747-hard-isnegativenumber/info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
difficulty: hard
title: IsNegativeNumber
tags: number, template literal
author:
github: ahrjarrett
name: andrew jarrett

1 change: 1 addition & 0 deletions questions/25747-hard-isnegativenumber/template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type IsNegativeNumber<T extends number> = any
13 changes: 13 additions & 0 deletions questions/25747-hard-isnegativenumber/test-cases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Equal, Expect } from '@type-challenges/utils'

type cases = [
Expect<Equal<IsNegativeNumber<0>, false>>,
Expect<Equal<IsNegativeNumber<number>, never>>,
Expect<Equal<IsNegativeNumber<-1 | -2>, never>>,
Expect<Equal<IsNegativeNumber<-1>, true>>,
Expect<Equal<IsNegativeNumber<-1.9>, true>>,
Expect<Equal<IsNegativeNumber<-100_000_000>, true>>,
Expect<Equal<IsNegativeNumber<1>, false>>,
Expect<Equal<IsNegativeNumber<1.9>, false>>,
Expect<Equal<IsNegativeNumber<100_000_000>, false>>,
]

0 comments on commit 3275c05

Please sign in to comment.