【发布时间】:2020-03-03 01:54:47
【问题描述】:
type A = "a" | "b";
type B = "c" | "d";
type C<Type extends A> = Type;
type D<Type extends B> = Type;
type Auto<Type extends (A|B)> = Type extends A ? C<Type> : D<Type>; //It throws error!
//Type 'Type' does not satisfy the constraint 'B'.
Auto 类型具有泛型。 Type 是 A|B,与 "a" | "b" | "c" | "d" 相同。而A 等于"a" | "b"。但是为什么我不能使用Type extends A ? C<Type> : D<Type>? D<Type> 抛出错误“类型‘类型’不满足约束‘B’。”。
【问题讨论】:
标签: typescript generics conditional-types