问题描述
假设我有以下 3 种类型:
type Apple = {
type: "apple"
}
type Banana = {
type: "banana"
}
type Fruit<T extends "apple" | "banana"> = T extends "apple" ? Apple : Banana
我有一个通用函数如下:
function fruit<T extends "apple" | "banana">(fr: Fruit<T>) {
if (fr.type === "apple") {
const element = fr
}
}
为什么 element
仍然是 Fruit<T>
而不是 Apple
?有没有办法让条件类型的有区别的联合工作?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)