TypeScript 笔记

函数式组件

TypeScript 中函数参数为对象时的写法

const fn = (props: {
  type: 'history' | 'nominate'; //历史还是推荐
  process: 'set' | 'get'; // 保存还是读取
}) => {
  const { type, process } = props;
  ...
};

直观一点:

export interface Props {
  type: 'history' | 'nominate'; // 历史还是推荐
  process: 'set' | 'get'; // 保存还是读取
}

const fn = (props: Props) => {
  const { type, process } = props;
};