我正在嘗試將自定義函式型別記錄為物件的一部分,任何幫助將不勝感激:
問題的背景
這是一個簡單的物件宣告,其中包含一些函式屬性(addCoordinate、addCoordinateOne、addCoordinateTwo),我們將作為 3 個展示進行討論,以及為什么這些都不起作用。
/**
* @typedef {Object} Point
* @property {number} x - The X Coordinate
* @property {number} y - The Y Coordinate
*/
/**
* @typedef {Object} Shape
* @property {Point} startCoordinate - the starting coordinate
* @property {Point[]} coordinates - An array of point coordinates
* @property {(x:string, y:string) => void} addCoordinate - Updates the point
* @property {addCoordinateOne} addCoordinateOne - Updates the point
* @property {addCoordinateTwo} addCoordinateTwo - Updates the point
*/
/** @type {Shape} */
const square = {}
展品 A
@property {(x:string, y:string) => void} addCoordinate - Updates the point
這完全有效,但不能像我需要的那樣可重復使用。

展品 B
/**
* @typedef {Function} addCoordinateOne
* @param {string} X
* @param {string} Y
*/
這種作業,因為它檢測自定義函式型別。但它不能正確決議引數。我確保遵循@typedef標簽的檔案:

展品 C
/**
* @function addCoordinateTwo
* @param {string} X
* @param {string} Y
*/
這完全失敗了。盡管是 JSDoc@function檔案推薦的方法。

如果使用@callback語法,則為每個引數提供描述:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/459391.html
標籤:javascript 打字稿 视觉工作室代码 jsdoc
下一篇:已解決與SQLServer的連接:java.sql.SQLException:找不到適合jdbc:sqlserver的驅動程式
