ts 常用片段
returnType , Pick, Omit
type Test={
name:string,
age:number,
call:()=>void,
color:string,
}
type PickTest=Pick<Test, 'name'|'color' >//顾名思义, 挑出来
type OmitTest=Omit<Test, 'name'|'color'>
type T1 = Exclude<"a" | "b" | "c", "a" | "b">; // "c"
type T2 = Exclude<string | number | (() => void), Function>; // string | number
function foo(x: string | number): string | number { /*..*/ }
type FooType = ReturnType<foo>; // string | numbe
type Person = Test & { age1: number };
interface IPerson extends Test { age1: number };
// // 获取参数类型
// import { Button } from 'library' // 但是未导出props type
type ButtonProps = React.ComponentProps<typeof Button> // 获取props
type AlertButtonProps = Omit<ButtonProps, 'onClick'> // 去除onClick
// const AlertButton: React.FC<AlertButtonProps> = props => (
// <Button onClick={() => alert('hello')} {...props} />
// )```