Handbook

Utility Types

2025-01-08

Parameters

提取函数参数的类型:

type T3 = Parameters<typeof f1>;
type T3 = [arg: {
a: number;
b: string;
}]

碰到的使用场景是在 [[Astro]] 中导入时,希望同样也支持导入方法的部分 Props:

type SimpleCardProps = Parameters<typeof SimpleCard>[0];
interface Props {
size?: Pick<SimpleCardProps, 'size'>['size'];
className?: string;
}