Skip to content

Add function parameter constraint examples to numeric comparison types#1357

Merged
sindresorhus merged 3 commits intosindresorhus:mainfrom
derodero24:docs/greater-than-parameter-example
Feb 14, 2026
Merged

Add function parameter constraint examples to numeric comparison types#1357
sindresorhus merged 3 commits intosindresorhus:mainfrom
derodero24:docs/greater-than-parameter-example

Conversation

@derodero24
Copy link
Contributor

Closes #957

Adds a second @example block to GreaterThan showing how to use it as a function parameter constraint.

Users attempting to use GreaterThan<N, 0> directly as a parameter type get never because the generic is unresolved. The added example demonstrates the correct pattern using a conditional type:

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

Copy link
Collaborator

@som-sm som-sm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please resolve the conflict.

setPositive(-1);

// @ts-expect-error
setPositive(0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add similar examples to LessThan, LessThanOrEqual and GreaterThanOrEqual.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added similar examples to all three types and resolved the conflict.

@derodero24 derodero24 changed the title GreaterThan: Add example for function parameter constraint Add function parameter constraint examples to numeric comparison types Feb 14, 2026
@derodero24 derodero24 force-pushed the docs/greater-than-parameter-example branch from 772c668 to 157ebd9 Compare February 14, 2026 05:08
@som-sm som-sm force-pushed the docs/greater-than-parameter-example branch from bfde8c2 to f18995b Compare February 14, 2026 07:30
@sindresorhus sindresorhus merged commit 24be93d into sindresorhus:main Feb 14, 2026
7 checks passed
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.

Can i use GreaterThan as parameter type?

3 participants