如何在JSDOC(或Typescript?)中记录函数自定义类型并引用它们,以便VSCODE IntelliSense起作用
我正在尝试将自定义函数类型作为对象的一部分进行记录,任何帮助都将不胜感激:
问题的上下文
是一个简单的对象声明,其中有某些函数属性(AddCoorcorion,AddCoordionAne,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
This作品的全部作品,但不能像我需要的那样重复使用。
展览b
/**
* @typedef {Function} addCoordinateOne
* @param {string} X
* @param {string} Y
*/
这是一种的作品,因为它检测到自定义函数类型。但是它不能正确解析参数。我确保遵循@TyPedef
标签的文档: https://jsdoc.app.app/tags-tags-typedef.html
/I.SSTATIC.NET/4LBHS.png“ rel =“ noreferrer”>
”
/**
* @function addCoordinateTwo
* @param {string} X
* @param {string} Y
*/
https://i.sstatic.net/4lbhs.png 完全失败。尽管是JSDOC的@function
文档推荐的方法。
https://jsdoc.app/tags-function.html
I am trying to document custom function types as part of an object, any help would be greatly appreciated:
Context of the problem
Here is a simple object declaration with some function properties (addCoordinate, addCoordinateOne, addCoordinateTwo) which we will go over as 3 exhibits, and why none of these work.
/**
* @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 = {}
Exhibit A
@property {(x:string, y:string) => void} addCoordinate - Updates the point
This works fully, but isn't reusable like I need.
Exhibit B
/**
* @typedef {Function} addCoordinateOne
* @param {string} X
* @param {string} Y
*/
This sort of works, as it detects the custom function type. But it doesn't parse parameters properly. I made sure to follow the documentation for the @typedef
tag:
https://jsdoc.app/tags-typedef.html
Exhibit C
/**
* @function addCoordinateTwo
* @param {string} X
* @param {string} Y
*/
This fails completely. Despite being the recommended approach by JSDoc's @function
documentation.
https://jsdoc.app/tags-function.html
The Question
Is there any way I could get Exhibit B or C working like Exhibit A?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将展览a更改为typedef:
编辑:或逐字化,可以使用
@callback
标签:
然后根据需要重复使用:
结果:
如果使用速记语法,则没有paramater说明可用。

如果使用

@Callback
语法,则为每个Paramater提供了描述:You can change Exhibit A to a typedef:
Edit: Or more verbosely, you can use the
@callback
tag:Then reuse as needed:
Result:
If using the shorthand syntax, no paramater descriptions are available.

If using the

@callback
syntax, descriptions are provided for each paramater: