Skip to content

Conversation

@som-sm
Copy link
Collaborator

@som-sm som-sm commented Oct 19, 2025

GreaterThanOrEqual currently doesn’t distribute A and B before checking whether A extends B.

export type GreaterThanOrEqual<A extends number, B extends number> = number extends A | B
? never
: A extends B ? true : GreaterThan<A, B>;

As a result, if A is 1 and B is 1 | 2, the condition A extends B satisfies, causing the type to return true and completely ignore the | 2 part in B.

This PR fixes the behavior by distributing A and B before performing the check.

type Current = GreaterThanOrEqual<1, 1 | 2>;
//=> true

type Fixed = GreaterThanOrEqual<1, 1 | 2>;
//=> boolean

Similar issue happens with LessThan because it's dependent on GreaterThanOrEqual.

type Current = LessThan<1, 1 | 2>;
//=> false

type Fixed = LessThan<1, 1 | 2>;
//=> boolean

@som-sm som-sm requested a review from sindresorhus October 19, 2025 13:42
@som-sm som-sm changed the title GreaterThanOrEqual / LessThan: Fix behaviour when instantiated with operands like N and N | N + >0 GreaterThanOrEqual / LessThan: Fix behaviour with operands like N and N | N + >0 Oct 19, 2025
@claude

This comment was marked as resolved.

@som-sm
Copy link
Collaborator Author

som-sm commented Oct 19, 2025

Also, currently GreaterThan<number, 10> returns never which seems incorrect, should have been boolean instead. Similar happens with all the other similar types. Will open a separate PR for this.

@sindresorhus sindresorhus merged commit b2caa3f into main Oct 19, 2025
7 checks passed
@sindresorhus sindresorhus deleted the fix/gte-lt--with-unions branch October 19, 2025 16:16
som-sm added a commit that referenced this pull request Nov 7, 2025
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.

3 participants