Skip to content

GreaterThan / LessThan / GreaterThanOrEqual / LessThanOrEqual: Fix behavior with the number type#1363

Merged
sindresorhus merged 2 commits intomainfrom
fix/greater-than-with-number
Feb 9, 2026
Merged

GreaterThan / LessThan / GreaterThanOrEqual / LessThanOrEqual: Fix behavior with the number type#1363
sindresorhus merged 2 commits intomainfrom
fix/greater-than-with-number

Conversation

@som-sm
Copy link
Collaborator

@som-sm som-sm commented Feb 9, 2026

Currently, if either argument is number, the result is never. Instead, the result should be boolean.


In #1357, the following example is being added to GreaterThan's doc:

declare function setPositive<N extends number>(value: GreaterThan<N, 0> extends true ? N : never): void;

But this function can be called with a negative number if the type of the parameter is number, like:

setPositive(-1 as number); // Works

Because currently GreaterThan<number> returns never and never extends true.

Changing GreaterThan<number> to return boolean prevents this because boolean doesn't extend true. And in case you wanted to allow the number type, you could simply do true extends GreaterThan<N, 0> instead of GreaterThan<N, 0> extends true.


This PR also applies similar fix to LessThan, GreaterThanOrEqual and LessThanOrEqual.

@som-sm som-sm requested a review from sindresorhus February 9, 2026 10:17
@som-sm som-sm force-pushed the fix/greater-than-with-number branch from 5315da4 to 77b20e3 Compare February 9, 2026 10:20
@som-sm som-sm marked this pull request as draft February 9, 2026 10:21
Repository owner deleted a comment from claude bot Feb 9, 2026
@som-sm som-sm force-pushed the fix/greater-than-with-number branch from 77b20e3 to 7dd91dc Compare February 9, 2026 10:29
Repository owner deleted a comment from claude bot Feb 9, 2026
@som-sm som-sm changed the title GreaterThan: Fix behavior with the number type GreaterThan / LessThan / GreaterThanOrEqual / LessThanOrEqual: Fix behavior with the number type Feb 9, 2026
@som-sm som-sm force-pushed the fix/greater-than-with-number branch from 7dd91dc to 232157a Compare February 9, 2026 10:33
Repository owner deleted a comment from claude bot Feb 9, 2026
@som-sm som-sm force-pushed the fix/greater-than-with-number branch from 232157a to 3a5ccdd Compare February 9, 2026 10:35
Repository owner deleted a comment from claude bot Feb 9, 2026
Repository owner deleted a comment from claude bot Feb 9, 2026
@som-sm som-sm marked this pull request as ready for review February 9, 2026 10:40
@sindresorhus sindresorhus merged commit cfea505 into main Feb 9, 2026
6 checks passed
@sindresorhus sindresorhus deleted the fix/greater-than-with-number branch February 9, 2026 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants