type FilterOptional = Pick ? K : never; }[keyof T], undefined>>; type FilterNotOptional = Pick ? never : K; }[keyof T], undefined>>; type PartialEither = { [P in Exclude, K>]-?: T[P]; } & { [P in Exclude, K>]?: T[P]; } & { [P in Extract]?: undefined; }; /** * 属性二选一 * @example * type RawType = { a: 'a', b: 'b' } * type ResType = EitherOr // 只能存在 a 或者 b * * const a: ResType = { a: 'a' } * const b: ResType = { b: 'b' } * const c: ResType = { a: 'a', b: 'b', } // 报错 */ type EitherOr = (PartialEither, L> | PartialEither, R>) & Omit; export default EitherOr;