Skip to content

Can i use GreaterThan as parameter type? #957

Open
@enccode

Description

@enccode

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions