【发布时间】:2020-08-08 03:17:22
【问题描述】:
我有两种类型的并集,其中一种是空 obj。
type U = {} | { a: number } // | { b: string } | { c: boolean } ....
我想从联合中排除空对象但是Exclude 没有帮助
type A = Exclude<U, {}>
// A = never
我尝试使用as const,但结果相同
const empty = {} as const
type Empty = typeof empty
type U = Empty | { a: number }
type A = Exclude<U, Empty>
//type A = never
额外的讽刺是排除其他属性很简单
type B = Exclude<U, { a: number }>
// type B = {}
那么是否可以从联合中的其他接口中排除一个空接口?
【问题讨论】: