我正在尝试编写一个可以按如下方式使用的 Typescript 泛型类型:
/* All properties are nullable */
type A = {
a: string | null,
b: string | null;
}
type G_A = MyType<A>; // A | undefined
/* At least one property is not nullable */
type B = {
a: string;
b: string | null;
}
type G_B = MyType<B>; // B
因此的目标是,如果的所有属性都被允许,MyType<T>
它就返回,但如果不允许,它就只返回。T | undefined
T
null
T
我有点不知道该如何处理这个问题,所以我无法分享我尝试过的任何方法。