如何使用JSDoc注释Express中间件? [英] How to annotate Express middlewares with JSDoc?

查看:109
本文介绍了如何使用JSDoc注释Express中间件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试记录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 @typedefs 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

  1. 安装快递类型npm install --save-dev @types/express
  2. 像往常一样@param {e.Response} res
  3. 使用 e.Response

更多类型

  • 在文件/node_modules/@types/express/index.d.ts
  • 对于响应,它是 e.Response ,因为:
  • More types

    • in file /node_modules/@types/express/index.d.ts
    • for Response it is e.Response because:
    • ... 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆