如何使用JSDoc注释Express中间件? [英] How to annotate Express middlewares with JSDoc?
问题描述
我正在尝试记录Express中间件,但是WebStorm中的内置验证工具告诉我在以下JSDoc块中错误地分配了类型:
I'm trying to document an Express middleware, but the build-in validation tool in WebStorm tells me that types are incorrectly assigned in the following JSDoc block:
/**
* My middleware.
*
* @param {Object} req
* @param {Object} res
* @param {Function} next
* @return {Object}
*/
exports.show = function(req, res, next) {
...
};
在Express消息来源中,我找不到任何@typedef
可以帮助我.另外,我想避免使用@param {*}
之类的东西.
In Express sources, I didn't find any @typedef
s to help me. Also, I want to avoid things like @param {*}
.
使用JSDoc记录Express中间件的正确方法是什么?感谢您的帮助.
What is the correct way to document Express middleware using JSDoc? Thanks for any help.
推荐答案
使用DefinitelyTyped
- 安装快递类型
npm install --save-dev @types/express
- 像往常一样
@param {e.Response} res
使用 e.Response
更多类型
- 在文件
/node_modules/@types/express/index.d.ts
中
- 对于响应,它是 e.Response ,因为:
- in file
/node_modules/@types/express/index.d.ts
- for Response it is e.Response because:
More types
...
declare namespace e {
...
export interface Response extends core.Response { }
...
...
declare namespace e {
...
export interface Response extends core.Response { }
...
安装类型.框架> Javascript>库> @ types/express
install types via Settings > Languages & Frameworks > Javascript > Libraries > @types/express
这篇关于如何使用JSDoc注释Express中间件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!