You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
解释一下,当泛型 T 类型未知时,对这部分条件类型 T extends X ? 1 : 2 的推断会被推迟。而对于类型 <T>() => T extends X ? 1 : 2,由于其是一个函数,返回值包含了推迟的条件类型,所以该类型也被推迟。
这样一来,判断类型 <T>() => T extends X ? 1 : 2 是否可赋值(extends)给 <T>() => T extends Y ? 1 : 2 的条件就是:
第一个 T 可赋值给第二个 T,或反之
X 和 Y 类型完全相同
1 可以赋值给 1
2 可以赋值给 2
// Two conditional types 'T1 extends U1 ? X1 : Y1' and 'T2 extends U2 ? X2 : Y2' are related if
// one of T1 and T2 is related to the other, U1 and U2 are identical types, X1 is related to X2,
// and Y1 is related to Y2.
Equals
的实现来源于:microsoft/TypeScript#27024 (comment)
The text was updated successfully, but these errors were encountered: