如何使用Jsdocs和Typescript记录功能组件的反应

时间:2020-10-14 15:44:20

标签: reactjs typescript document jsdoc react-functional-component

给出这个

type LocationWeather = {
  name: string;
  temperature: number;
};

type IndexProp = {
  savedLocationsWeather: LocationWeather[];
  favoriteLocationWeather: LocationWeather;
};


function Index({ savedLocationsWeather, favoriteLocationWeather }: IndexProp)

文档应该是什么样的?

我的第一个方法是:

/**
 * Home page displaying weather details of saved locations and favorite location
 * @param {object} props Component props
 * @param {LocationWeather[]} props.savedLocationsWeather Weather details of saved locations
 * @param {LocationWeather} props.favoriteLocationWeather Weather details of favorite location
 * @return {TSX.Element}
 */

但是:

  1. 我不确定这是否是指定保存的LocationsWeather的数组类型的正确方法,如

    * @param {Array} props.savedLocationsWeather Weather details of saved locations

  2. 我也不确定将LocationWeather指定为jsdoc类型是正确的,

    * @param {Locationweather} props.favoriteLocationWeather Weather details of favorite location

  3. 甚至还有TSX.Element类型的东西,例如

    * @return {TSX.Element}

最后,我应该定义PropTypes as done here

0 个答案:

没有答案