这是我来这里寻求建议之前最后一次失败的尝试。我做错了什么吗?
interface Something {
id: string;
name: string | null;
}
interface AnotherThing {
id: string;
name: string;
}
type ExcludeNullableFields<A> = {
[K in keyof A as A[K] extends string | null ? K : never]: A[K] ;
};
type NamelessThing = ExcludeNullableFields<Something>;
// desired outcome: { id: string }
type NamedThing = ExcludeNullableFields<AnotherThing>;
// desired outcome: { id: string; name: string }