我想在一个函数中链接 2 个泛型类型,并通过检查其中之一来对这两种类型使用缩小范围。这样做的正确方法是什么?
type A = 'A';
type B = 'B';
type AB = A | B
type ComplexType<T> = {value: T}
const f = (next: ComplexType<A>) => {}
const builder = <T extends AB>(value: T) => (next: ComplexType<T>) => {
if (value === 'A') {
f(next) // expect next is ComplexType<A> but got error
}
}
Run Code Online (Sandbox Code Playgroud)