type One = (() => 1) & (() => 2);
type Two = { (): 1; (): 2; };
type MutuallyAssignable = One extends Two ? Two extends One ? true : false : false;
// ^? true
function three(): 1;
function three(): 2;
function three() { return 42 }
type Three = typeof three;
class C {
four(): 1;
four(): 2;
four() { return 42 }
}
type Four = C["four"];
type T<F> = F extends (...args: any[]) => infer R ? R : unknown;
type T01 = T<One>;
// ^? 2
type T02 = T<Two>;
// ^? 2
type T03 = T<Three>;
// ^? 2
type T04 = T<Four>;
// ^? 2
1条答案
按热度按时间hgncfbus1#
infer
在遇到交集时总是取最后一个重载(这实际上只是描述重载的另一种方式),不管你如何定义它。最后一个重载是交集中的最后一个成员或代码中的最后一个定义:Playground