import { ComponentType } from 'react'; /** * TS 无法直接 extends Union Type,但是可以 extends 一个 TypeAlias ```ts // 示例用法 export interface ButtonProps extends Combine< StyledProps, React.ButtonHTMLAttributes > {} ``` */ export type Combine = A & B & C & D & E & F; /** * 获取类型中值类型是指定类型的属性名 ```ts // 示例用法 type A = { foo: string; bar: number; }; // B is "foo" type B = MatchPropertyNames; ``` */ export type MatchPropertyNames = { [P in keyof S]: S[P] extends T ? P : never; }[keyof S]; /** * 获取类型的子集,只包含值为指定类型的属性 ```ts // 示例用法 type A = { foo: string; bar: number; }; // B is { foo: string } type B = MatchProperties; ``` */ export type MatchProperties = Pick>; /** * 获取已有组件的 props 类型 ```ts // 示例用法 function Foo(props: { foo: string, bar: number }) { return
; } // FooProps is { foo: string, bar: number } type FooProps = InferProps; ``` */ export type InferProps = C extends ComponentType ? P : never;