如何让Typedoc识别类型定义内的TSDoc注释?
Typedoc无法抓取数组类型内部对象属性的TSDoc注释
问题分析
你的CellSetAxesSelection类型直接定义为{...}[](数组包裹匿名对象),Typedoc默认不会解析匿名对象的属性注释,只会识别到这是一个数组类型,因此内部属性的TSDoc无法在生成文档中显示。
解决方案
方案1:提取内部对象为命名类型
将数组内部的匿名对象提取成单独的命名类型,让Typedoc能够识别并解析其属性注释:
/** * The tuples and levels corresponding to the selected positions (which can be headers in a table or ticks on a chart's axes). */ export type CellSetAxisSelectionItem = { /** * The id of the cellset axis corresponding to this part of the selection: 0 for column headers, and 1 for row headers and static headers. * COLUMNS: 0 | ROWS: 1 */ id: AxisId; // This attribute is called `hierarchies` even though it contains levelCoordinates, because the `CellSetSelection` interface is made to be close to CellSet. /** * The selected levels (for instance if the user selected the header of a column representing a level in a table). */ hierarchies?: ( | LevelCoordinates | { dimensionName: "Measures"; hierarchyName: "Measures" } )[]; /** * The partial tuples corresponding to the selected row or column headers. * For instance, consider a table whose first 3 columns represent Currency, City and Date. * Assume that the 1rst row represents [USD, New York, Today]. * The user selected the 2nd cell on that row. * Then there would be one position: [USD, New York]. * If the user now selects the 3rd cell on that row, then "Today" would only be present on the partial tuple. */ positions?: Tuple[]; /** * The index of each selected position in `data.axes[axisIndex].positions`. * `positionIndices` always has the same length as the `positions` attribute above. * It can be used to retrieve the full tuples corresponding to the selected row or column headers. * For instance in the previous example, it allows to retrieve "Date = Today", even if the user clicked on the 2nd cell of the 1rst row. */ positionIndices?: number[]; }; export type CellSetAxesSelection = CellSetAxisSelectionItem[];
方案2:升级Typedoc到最新版本
旧版本的Typedoc对匿名数组元素的注释支持存在缺陷,运行以下命令升级到最新版:
npm update typedoc
方案3:检查Typedoc配置
确保你的typedoc.json配置中没有禁用属性注释解析,默认配置无需修改;若有自定义配置,确认excludeExternals、excludePrivate等选项未误屏蔽目标类型。
内容的提问来源于stack exchange,提问作者Adam Le Roux
相关产品推荐
相关产品推荐

