需求
- 在写koa中间件时,没有代码提示,如
app.js
const app = new Koa();
app.use(mongo());
middleware/mongo.js
export const mongo = () => {
return (ctx, next) => {
ctx.request
next();
}
}
解决
利用jsdoc注释补全提示
/**
* mongodb中间件
* @returns {(ctx:import("koa").ParameterizedContext,next:import("koa").Next)=>void}
*/
export const mongo = () => {
return (ctx, next) => {
next();
}
}
效果图
t1
t2
t3
end