不能使用 type-fest GreaterThan 作为参数类型

问题描述 投票:0回答:1

我尝试使用 type-fest GreaterThan 类型作为函数参数,但出现错误

当我编写以下函数时:

import type {GreaterThan} from 'type-fest'

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

还有...:

printNumberOfBooks(2)

我收到以下打字稿错误:

“number”类型的参数不可分配给“never”类型的参数

我花了几个小时......我没有找到解决方案

type-fest GreaterThan 类型官方文档

typescript泛型官方文档

javascript node.js typescript typescript-generics type-fest
1个回答
0
投票

看看这个 大声喊出nadameu

© www.soinside.com 2019 - 2024. All rights reserved.