为什么我的函数的参数显示为布尔值(使用 JSDocs),而事实并非如此?

问题描述 投票:0回答:1

我记录了我对React的tic-tac-toe教程的复制,我不明白为什么我的函数的参数显示为布尔值(使用JSDocs),而事实并非如此。

这是当我将光标悬停在函数上时出现的内容: View with IntellijSense of the function

这是我的函数的代码:

/**Return the game board.
 * 
 * @param {boolean} xIsNext Allows to show a text that tell which player is the next.
 * @param {string[]} squares The current board which will be update at the next action.
 * @param {*} onPlay A function that allows to re-render the board.
 * @returns the JSX structure of the board.
 */
function Board({xIsNext, squares, onPlay}) {
  // ...
}

事实上它是在花括号中吗?或者是React的存在?还是其他原因?

javascript reactjs jsdoc
1个回答
0
投票

因为

Board
组件采用单 props 参数。不是多参数

最好为

BoardProps
定义一个类型,如下所示

/**
 * The board properties.
 * 
 * @typedef {object} BoardProps
 * @property {boolean} xIsNext Allows to show a text that tell which player is the next.
 * @property {string[]} squares The current board which will be update at the next action.
 * @property {*} onPlay A function that allows to re-render the board.
 * /

/**
 * Board component
 * 
 * @param {BoardProps} props The board props
 * @returns {React.ReactElement}
 */
function Board({ xIsNext, squares, onPlay }) {
  // ...
}

© www.soinside.com 2019 - 2024. All rights reserved.