比方说,我有两种类型A
和B
一个函数f
,它接受一个 rest 参数作为参数,但我希望它至少有一个 type 的参数A
。有没有办法在使用 Typescript 的编译时拥有这样的东西?
我尝试了以下
type A
type B
function f (...o: (A | B)[])
当我打电话时f
const a: A = ...
const b0: B = ...
const b1: B = ...
f(a, b0, b1) // Fine
f(b0, a, b1) // Fine
f(b0, b1, a) // Still fine
f(b0, b1) // works but I don't want it to work because I need f to accept at least one argument which has a type A