Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can i use GreaterThan as parameter type? #957

Open
enccode opened this issue Sep 23, 2024 · 3 comments
Open

Can i use GreaterThan as parameter type? #957

enccode opened this issue Sep 23, 2024 · 3 comments
Labels
documentation good first issue Good for newcomers help wanted Extra attention is needed

Comments

@enccode
Copy link

enccode commented Sep 23, 2024

Newbie here...

Is it possible to use GreaterThan type for the function/method parameters?

when I write the following function:

import type {GreaterThan} from 'type-fest'

function printNumberOfBooks <N extends number> (numberOfBooks: GreaterThan<N, 0>): void {
    console.log(numberOfBooks)
}

and... :

printNumberOfBooks(2)

I get the following typescript error:

Argument of type 'number' is not assignable to parameter of type 'never'

It took me hours... I didn't find a solution

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • The funding will be given to active contributors.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@fregante fregante added the question Further information is requested label Sep 24, 2024
@sindresorhus
Copy link
Owner

Answer here: https://www.reddit.com/r/typescript/comments/1fs64kb/can_i_use_greaterthan_as_parameter_type/

Would be nice to include an example of this in the doc comment of the type.

@sindresorhus sindresorhus added help wanted Extra attention is needed good first issue Good for newcomers documentation and removed question Further information is requested labels Sep 29, 2024
@enccode
Copy link
Author

enccode commented Sep 29, 2024

I asked this question 2 hours ago on reddit...came to post the link here and saw you did it faster... I would be happy if I could help you by putting the examples in the documentation... but I think it's better if someone with more experience in TypeScript does it... Thank you for your time and making very useful tools.

@ikelax
Copy link

ikelax commented Sep 30, 2024

Answer here: reddit.com/r/typescript/comments/1fs64kb/can_i_use_greaterthan_as_parameter_type

Would be nice to include an example of this in the doc comment of the type.

There are already examples in the doc comment of GreaterThan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants