TL;DR: 因为无论I 是什么,它都必须可分配给所有函数类型T 的参数。
这是因为函数参数是反变体。这只是意味着要使用一个函数代替另一个函数,它的参数类型必须与另一个函数相同或更通用。看一个例子就很明显了:
type f: (arg: string) => string;
type g: (arg: "foo") => string;
// f is assignable to g, since a function expecting
// to receive any string should have no problem accepting
// the specific string "foo".
// However, the reverse isn't true. You can't assign g to f,
// since g expects to receive exactly the string "foo" for its
// argument, but if it's used in place of f, it can receive any string.
换句话说,f 可以分配给g,因为g 的参数可以分配给f。这种逆转是相反部分。
因此,如果T 是某个神秘函数类型(...args: I[]) => R 的子类型,则自变量逆变告诉我们I 必须可分配给T 的自变量类型。
因此,T extends (...args: (infer I)[]) => infer R 告诉 typescript 推断出某个单一类型 I 以便可以使用 I 代替 T 的 any 参数。
因此,对于您的类型X,无论I 是什么,它都必须可以分配给两个参数。由于参数类型分别是number 和string,我们问:什么类型可以分配给这两个?
好吧,number & string。
*更多信息,您可能有兴趣阅读co and contra-variance。